InetAddress 클래스
InetAddress 클래스는 인터넷 도메인이나 호스트를 IP 주소로 전환하는 기능을 함.
InetAddress 클래스의 특징
- 클래스는 별도의 생성자를 제공하지 않으며, 객체를 생성하기 위해 getByName()메소드와 같이 정적 객체 생성 메소드를 사용
- InetAddress 객체를 생성하면 수정할 수 없다
- InetAddress 는 일반적으로 IPv4 주소를 사용 (IPv6는 Inet6Address)
import java.net.InetAddress;
public class InetadrEx {
public static void main(String[] args) {
InetAddress address[] = null;
try {
address = InetAddress.getAllByName(args[0]);
for(InetAddress each : address) {
//호스트 이름 반환
System.out.println("name : " + each.getHostName());
//InetAddress의 IP주소해 해당하는 문자열 을 얻음
System.out.println("addr : " + each.getHostAddress());
//InetAddress 객체의 전체 도메인 이름 을 얻는다
System.out.println("Canonical : "+ each.getCanonicalHostName());
}
} catch (Exception e) {
// TODO: handle exception
}
}
}