代码:- public class PingByInetAddress {
- public static void main(String[] args) {
- try {
- InetAddress address=InetAddress.getByName("23.34.145.55"); // oracle的地址
- System.out.println(address.toString());
- System.out.println(address.getHostName()); // 主机别名
- System.out.println(address.getCanonicalHostName()); // 主机名
- InetAddress address1=InetAddress.getByName("218.30.66.101"); // 新浪地址
- System.out.println(address1.getCanonicalHostName()); // 为什么得不到呢?
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- System.out.println("sorry, cann't find this host! ");
- }
-
- }
- }
复制代码 运行结果:
/23.34.145.55
a23-34-145-55.deploy.akamaitechnologies.com
a23-34-145-55.deploy.akamaitechnologies.com
218.30.66.101
为什么oracle网址两种方法返回的主机别名和主机名相同?
为什么sina网址返回的主机别名是个ip地址? |