//通过名称(ip字符串or主机名)来获取一个ip对象。 InetAddress ip = InetAddress.getByName("www.baidu.com");//java.net.UnknownHostException System.out.println("addr:"+ip.getHostAddress()); System.out.println("name:"+ip.getHostName());
结果输出:
addr:119.75.213.61 name:www.baidu.com
亲测好使。
原文地址:https://www.cnblogs.com/zjiacun/p/8493401.html
时间: 2024-11-09 23:06:22