先看看代码
import java.net.InetAddress;
import java.net.UnknownHostException;
public class ipdz
{
/**
*
* @throws UnknownHostException
*/
public static void main(String[] args) throws UnknownHostException
{
InetAddress ip=InetAddress.getLocalHost();
ip=InetAddress.getByName("www.baidu.com");
System.out.println(ip.getHostAddress());
System.out.println(ip.getHostName());
}
}
运行后是
220.181.112.143
www.baidu.com
然后将ip=InetAddress.getByName("www.baidu.com");
改为ip=InetAddress.getByName("220.181.112.143");打印如下
220.181.112.143
220.181.112.143
为什么不是
220.181.112.143
www.baidu.com ???? |