//通过名称(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
亲测好使。