Java 获取指定主机IP
2018-10-07 本文已影响8人
黄一倚
import java.net.InetAddress;
import java.net.UnknownHostException;
public class GetIP {
public static void main(String[] args) {
InetAddress address = null;
try {
address = InetAddress.getByName("www.baidu.com");
} catch (UnknownHostException e) {
e.printStackTrace();
}
System.out.println(address.getHostName()+":"+address.getHostAddress());
System.exit(0);
}
}