代码如下:
1 public class Demo1 { 2 3 public static void main(String[] args) throws UnknownHostException { 4 //通过getByName("主机名或IP号")获取别人的ip地址对象 5 InetAddress inetAddress =InetAddress.getByName("183.232.231.172"); 6 System.out.println("IP地址:"+inetAddress.getHostAddress()); 7 System.out.println("主机名:"+inetAddress.getHostName()); 8 } 9 10 }
代码结果截图: