거꾸로 바라본 세상
Published 2015. 12. 16. 23:41
InetAddress 클래스 Language/Java
반응형

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

}

}

}


반응형

'Language > Java' 카테고리의 다른 글

[NIO] 파일 채널(FileChannel)  (0) 2016.04.06
달력만들기  (0) 2016.03.25
Java 줄바꿈 처리  (0) 2016.03.07
SocketAddress 클래스와 NetworkInterface 클래스  (0) 2015.12.17
단순 연결리스트(Simple Linked List)  (0) 2015.11.10
profile

거꾸로 바라본 세상

@란지에。

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!