public class getIPhost {
@Test
public void test1(){
try {
InetAddress IpName1 = InetAddress.getByName("172.16.32.2");
System.out.println(IpName1);
final InetAddress IpName2 = InetAddress.getByName("www.baidu.com"); // 通过域名获取地址
System.out.println(IpName2);
final InetAddress byName = InetAddress.getByName("127.0.0.1");
System.out.println(byName);
final InetAddress localHost = InetAddress.getLocalHost();
System.out.println(localHost);
// 获取ip
System.out.println(IpName2.getHostAddress());
// 获取地址的方法
System.out.println(IpName2.getHostName());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
InetAddress的使用代码
最新推荐文章于 2022-12-11 18:04:20 发布
关键词由CSDN通过智能技术生成