IPDisplay
import java.net.InetAddress;
import java.net.UnknownHostException;
public class IPDisplay {
public static void main(String[] args) {
// TODO Auto-generated method stub
InetAddress ia = null;
InetAddress[] ia2 = null;
try {
ia = InetAddress.getByName("www.daum.net");
//URL로 접근
System.out.println("server HostAddress : " + ia.getHostAddress());
//호스트주소 출력
System.out.println("server HostName : " + ia.getHostName());
//호스트이름 출력
System.out.println("====================================");
ia = InetAddress.getLocalHost(); //로컬호스트 정보관련
System.out.println("local HostAddress : " + ia.getHostAddress());
System.out.println("local HostName : " + ia.getHostName());
System.out.println("==================================");
ia2 = InetAddress.getAllByName("www.daum.net");
//InetAddress 클래스의 배열 형태로 데이터 반환
//다음의 URL 주소로 호스트 주소를 얻음
for (InetAddress aa : ia2) {
System.out.println(aa.getHostAddress());
System.out.println(aa.getHostName());
}
} catch (UnknownHostException e) {
System.out.println("해당 사이트는 유효하지 않습니다.");
}
}
}