InetAddress的创建与访问:
static InetAddress[ ] getAllByName(String host)
static InetAddress getByName(String host)
static InetAddress getLocalHost()
byte[] getAddress()
这些静态方法返回的实例可以做为套接字的参数来指定一个主机。方法的参数可以是一个域名也可以是一个代表数字类型地址的字符串。
getAddress()方法返回一个适当长度的字节数组,代表地址的二进制的形式。Inet4Address实例,该数组长4个字节;如果是 Inet6Address实例,则长16字节。
InetAddress: 字符串表示
String toString()
String getHostAddress() //单一的数字型地址表示形式
String getHostName() //主机名,没有经过解析
String getCanonicalHostName() //尝试对地址进行解析,获取主机的全名,如bam.example.com
InetAddress: 检测属性
boolean isAnyLocalAddress() //本地地址
boolean isLinkLocalAddress() //本地链接地址
boolean isLoopbackAddress() //回环地址
boolean isMulticastAddress() //多播地址
boolean isMCGlobal() //
boolean isMCLinkLocal()
boolean isMCNodeLocal()
boolean isMCOrgLocal()
boolean isMCSiteLocal()
boolean isReachable(int timeout)
boolean isReachable(NetworkInterface netif, int ttl, int timeout)
isMC...()形式的方法检测多播地址的各种范围,范围粗略地定义了到达该目的地址的数据报文从它的起始地址开始,所能传递的最远距离
isReachable方法检查是否真能与 InetAddress 地址确定的主机进行数据报文交换。该方法引起网络系统执行某些动作,即发送数据报文。系统不断尝试发送数据报文,直到指定的时间(以毫秒为单位)用完才结束。
isReachable(NetworkInterface netif, int ttl, int timeout) 指出数据报文必须经过指定的网络接口(NetworkInterface),并检查其是否能在指定的生命周期(time-to-live,TTL)内联系上目的地址。TTL 限制了一个数据报文在网络上能够传输的距离