2015년 10월 3일 토요일

[java]HttpClient 와 Swing 컴포넌트를 이용해 ip 팝업 띄우기 소스

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import javax.swing.JOptionPane;


@SuppressWarnings("deprecation")
public class WhatIsMyIp {

public static void main(String[] args) {
// HttpClient 생성
HttpClient httpclient = new DefaultHttpClient();

String url = "http://ipconfig.co.kr";
String charSet = "euc-kr";
//String charSet = "UTF-8";
String result = "";

try {
// HttpGet생성
HttpGet httpget = new HttpGet(url);

//System.out.println("executing request " + httpget.getURI());
HttpResponse response = httpclient.execute(httpget);

HttpEntity entity = response.getEntity();


if (entity != null) {
//System.out.println("Response content length: "
// + entity.getContentLength());
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(),charSet));

String line = "";
while ((line = rd.readLine()) != null) {
if(line.startsWith("IP address :")){
result = line;
}

}
}
httpget.abort();

httpclient.getConnectionManager().shutdown();

} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
httpclient.getConnectionManager().shutdown();
}

result = result.split(":")[1];
result = result.trim();
result = result.split(">")[1].split("<")[0];
//sSystem.out.println(result);

JOptionPane.showMessageDialog(null, result);

}

}

댓글 없음:

댓글 쓰기

[lunux]리눅스 폴더별 용량 확인

리눅스 폴더별 용량 확인 조회 하고자 하는 디렉토리 리스트가있는 경로로 이동후 du -h --max-depth=1