JAVA InetAddress类简单使用
- InetAddress类没有构造方法,需调用其static方法
方法 | 作用 |
---|---|
getLocalHost | 获取主机 |
getByNmae | 通过计算机名获取 |
getByAddress | 通过IP获取 |
InetAddress address1 = InetAddress.getLocalHost();
InetAddress address1 = InetAddress.getByName("host name");
byte[] bs=new byte[]{(byte) 192,(byte) 168,0,101};
InetAddress address1 = InetAddress.getByAddress(bs);
- 获取host信息
方法名 | 作用 |
---|---|
getHostName | 获取计算机名 |
getHostAddress | 获取IP地址 |
getAddress | 获取数组式IP地址 |