package clientFrame;
import java.io.IOException;
import java.net.*; public class tai {
public static void main(String[] args) throws UnknownHostException {
InetAddress ia;
ia=InetAddress.getByName("www.sina.com"); //搞笑吧
System.out.println("新浪主机ip是"+ia.getHostAddress());//因为我没联网所以无法获取网址的主机,ip
System.out.println("新浪主机的机名;"+ia.getHostName());
ia=InetAddress.getByName("www.soso.com");
System.out.println("so的ip:"+ia.getHostAddress());
System.out.println("so的主机名"+ia.getHostName()); }
}
总结:1.必须抛出异常。2.需要联网才能知道其他 网的ip和主机名