package Day4; import java.net.InetAddress; import java.net.UnknownHostException; public class InetAddressEx { public static void main(String[] args) throws UnknownHostException { //InetAddress 클래스는 IP번호를 처리할 때 사용하는 클래스이다.
InetAddress iaddr = InetAddress.getLocalHost(); //로컬 호스트를 이용한 InetAddress 객체를 생성한다. //getlocalhost : 로컬호스트를 이용해서 iaddr아이피 주소를 받아온다
System.out.printf("호스트 이름 : %s %n", iaddr.getHostName()); //호스트 이름을 문자열로 반환한다. //getHostName : 호스트네임을 이용해서 iadder호스트이름을 불러온다
System.out.printf("호스트 IP 주소 : %s %n", iaddr.getHostAddress()); //호스트에 대한 IP주소를 반환한다. //getHostAddress : 호스트어드레스를 이용해서 iadder의 호스트 IP주소를 받아온다
iaddr = InetAddress.getByName("java.sun.com"); // "java.sun.com"에 대응하는 InetAddress 객체를 반환한다. //getByName : 바이네임을 이용해서 모든 호스트이름들을 불러온다
System.out.printf("호스트 이름 : %s %n", iaddr.getHostName()); System.out.printf("호스트 IP주소 : %s %n", iaddr.getHostAddress()); //매개변수 host에 대응하는 InetAddress 배열을 반환한다.