InetAddress类
InetAddress是IP地址(也就是主机地址)类型。创建主机地址对象要靠InetAddress类的几个静态工厂方法。
InetAddress getByAddress(String host, byte[] addr):根据主机名和IP地址的各个字节创建IP地址对象。要把IP地址的高字节放在addr的低索引处。
InetAddress getByName(String host):仅根据主机名创建IP地址对象。函数会访问DNS服务器来获取host的IP地址的。
注:主机名既可以是域名,也可以是IP地址的字符串形式。例如,
InetAddress addr1 = InetAddress.getByName("222.34.5.7");
InetAddress addr2 = InetAddress.getByName("www.javathinker.org");
本机的域名是"localhost",IPv4地址是127.0.0.1.
InetAddress[] getAllByname(String host):返回主机host的所有IP地址对象所组成的数组。
InetAddress getByAddress(byte[] addr):仅根据IP地址的各个字节创建IP地址对象。
InetAddress getLocalHost():返回本机的IP地址对象。
String toString():返回“主机名/IP地址”字符串。
String getHostName():返回此IP地址的主机名。
byte[] getAddress():返回此IP地址的各个字节,高字节放在低索引处。
String getHostAddress():返回此IP地址的字符串形式。
boolean isReachable(int timeout):测试此IP地址的