标签:style color os ar java sp ad 时间 as
//经过dns查询后的结果会缓存起来,成功结果永久缓存,失败结果会缓存10s,通过下面的方法设置成功和失败的缓存时间
// 0为不缓存,-1为永不过期,其它单位为s
Security.setProperty("networkaddress.cache.ttl", "10");
Security.setProperty("networkaddress.cache.negative.ttl", "3");
//如果传入的是ip地址,则不会进行dns查询
InetAddress address=InetAddress.getByName("www.baidu.com");
//InetAddress.getByName()传入ip地址,再调用getHostName()不会因为查询dns失败而异常
System.out.println(address.getHostName());//www.baidu.com
System.out.println(address.getHostAddress());//180.97.33.107
System.out.println(Arrays.toString(address.getAddress()));//[-76, 97, 33, 107]
System.out.println(address.toString());//www.baidu.com/180.97.33.107
//equals()有相同的ip地址则相等;hashCode()根据ip地址计算
//System.out.println(address.equals(address2));
//System.out.println(address.hashCode());
//通过echo端口测试机器是不是可以访问
address.isReachable(1000);
//获取硬件网络口的信息
NetworkInterface inter=NetworkInterface.getByName("eth3");
System.out.println(inter.getDisplayName());
System.out.println(inter.getName());
标签:style color os ar java sp ad 时间 as
原文地址:http://www.cnblogs.com/mu-mu/p/4061982.html