반응형
InetAddress 클래스
==> IP주소를 다루기 위한 클래스
1. naver의 IP정보 가져오기
// www.naver.com의 IP정보 가져오기
InetAddress naverIp = InetAddress.getByName("www.naver.com");
System.out.println("HostName : " + naverIp.getHostName());
System.out.println("HostAddress : " + naverIp.getHostAddress());
System.out.println("toString : " + naverIp.toString());
System.out.println();
2. 내 컴퓨터의 정보도 가져올 수 있다.
// 자신의 컴퓨터의 IP정보 가져오기
InetAddress localIp = InetAddress.getLocalHost();
System.out.println("HostName : " + localIp.getHostName());
System.out.println("HostAddress : " + localIp.getHostAddress());
System.out.println("toString : " + localIp.toString());
System.out.println();
3. IP주소가 여러개인 호스트의 정보도 가져올 수 있다.
InetAddress[] naverArr = InetAddress.getAllByName("www.naver.com");
for(InetAddress ip : naverArr) {
System.out.println(ip);
}
반응형
'내가 보려고 정리하는 > JAVA' 카테고리의 다른 글
DB와 연결하여 Lprod자료 가져오기 (0) | 2023.01.27 |
---|---|
Network Test - TCP / UDP - TCP써보자! (0) | 2023.01.24 |
한 문서에서 다른 문서로 실행 문서를 이동시키기(forward, sendRedirect 방식) (2) | 2023.01.24 |
Servlet-request / response 사용해보기 (0) | 2023.01.20 |
Log4j (0) | 2023.01.18 |