java se 网络编程中遇到的问题
smuhm 2014-05-19 05:59:53 import java.net.InetAddress ;
public class InetAddressDemo{
public static void main(String args[]) throws Exception {// 所有异常抛出
InetAddress locAdd = null ;
InetAddress remAdd = null ;
locAdd = InetAddress.getLocalHost() ;// 得到本机
remAdd = InetAddress.getByName("http://www.baidu.com/") ;
System.out.println("本机的IP地址:" + locAdd.getHostAddress()) ;
System.out.println("MLDNJAVA的IP地址:" + remAdd.getHostAddress()) ;
System.out.println("本机是否可达:" + locAdd.isReachable(5000)) ;
}
};
Exception in thread "main" java.net.UnknownHostException: http://www.baidu.com/
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getByName(Unknown Source)
at InetAddressDemo.main(InetAddressDemo.java:7)