1
package javaday01;
import java.net.InetAddress;
public class IpDemo {
public static void main(String[] args) throws Exception{
//获取IP地址
InetAddress inet4Address=InetAddress.getLocalHost();
System.out.println("IP地址"+inet4Address.toString());
System.out.println("IP地址"+inet4Address.getHostAddress());
System.out.println("IP地址"+inet4Address.getHostName());
//获取一台任意主机的IP地址 1.有参数
InetAddress ia=InetAddress.getByName("www.huangliusong.com");
System.out.print(ia.toString());
}
}
输出结果
IP地址QO2QDWJGYCOQEQ7/192.168.52.1
IP地址192.168.52.1
IP地址QO2QDWJGYCOQEQ7
www.huangliusong.com/121.42.26.65