InetAddress类的总结

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());

你可能感兴趣的:(java,web)