InetAddress类的总结

2023-05-16

1.

InetAddress类没有构造方法,所以不能直接new出一个对象;

可以通过InetAddress类的静态方法获得InetAddress的对象;

InetAddress.getLocalHost();

InetAddress.getByName("");

2.

//获取本机的InetAddress实例  

InetAddress address = InetAddress.getLocalHost();  

System.out.println("计算机名" + address.getHostName());  

System.out.println("IP地址" + address.getHostAddress());  

byte[] bytes = address.getAddress();//获取字节数组形式的IP地址  

System.out.println("字节数组形式的Ip" + Arrays.toString(bytes));  

System.out.println(address);//直接输出InetAddress对象  

//根据机器名获取InetAddress实例  

//InetAddress address2 = InetAddress.getByName("USER-20160501VP");  

InetAddress address3 = InetAddress.getByName("192.168.249.1");  

ystem.out.println("计算机名" + address3.getHostName());  

System.out.println("IP地址" + address3.getHostAddress());

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

InetAddress类的总结 的相关文章

随机推荐