try{
//註解是列印的結果
// InetAddress adr = InetAddress.getLocalHost();
//向主機取得InetAddress物件
//InetAddress adr = InetAddress.getByName("google.com");//google.com/74.125.31.100
//向網域名稱取得InetAddress物件
byte[] ip={8,8,8,8};
InetAddress adr = InetAddress.getByAddress(ip);
//google-public-dns-a.google.com/8.8.8.8
//以ip取得主機名稱
System.out.println(adr.getHostAddress());
System.out.println(adr.getHostName());
System.out.println(adr);
}catch(UnknownHostException e){
System.out.println("Error 404");
}
}
沒有留言:
張貼留言