Java에서 웹 사이트의 IP 주소 검색
이 튜토리얼에서는 메서드를 사용할 것입니다. java.net.InetAddress.getByName() Java에서 웹 사이트 웹 서버의 IP 주소를 얻으려면 IP 주소의 표현 또는 도메인 이름 (예 : www.google.com.import java.net.InetAddress;Output:
import java.net.SocketException;
import java.net.UnknownHostException;
public class ServerAddress {
public static void main(String[] zero) throws SocketException {
InetAddress ServerAddress;
try{
ServerAddress= InetAddress.getByName("www.yahoo.fr");
//도메인 이름
System.out.println("Yahoo 서버 주소 = "+
ServerAddress.getHostName());
//야후 서버 IP 주소
System.out.println("도메인 이름 = "+
ServerAddress.getHostName());
System.out.println("서버의 IP 주소 Yahoo.com = "+
ServerAddress.getHostAddress());
System.out.println("서버의 IP 주소 Yahoo.fr = "+
InetAddress.getByName("www.yahoo.fr").getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
domain name = www.yahoo.comgetHostName(): 이 IP 주소의 시스템 이름을 반환합니다.
서버의 IP 주소 Yahoo.com = 46.228.47.115
서버의 IP 주소 Yahoo.fr = 77.238.184.150
getHostAdress(): 서버의 IPv4 주소를 반환합니다.
References:
Doc 오라클: InetAdress
Java에서 IP 주소 조작
TCP 소켓: Java의 클라이언트/서버