public static void main(String[] args) {
try {
Enumeration networkInterfaceEnum = NetworkInterface
.getNetworkInterfaces();
while (networkInterfaceEnum.hasMoreElements()) {
NetworkInterface eachNetworkInterfaceEnum = networkInterfaceEnum
.nextElement();
System.out.println("getName="
+ eachNetworkInterfaceEnum.getName());
System.out.println("getDisplayName="
+ eachNetworkInterfaceEnum.getDisplayName());
Enumeration inetAddressesNum = eachNetworkInterfaceEnum
.getInetAddresses();
while (inetAddressesNum.hasMoreElements()) {
InetAddress eachInetAddress = inetAddressesNum
.nextElement();
System.out.println(" getCanonicalHostName="
+ eachInetAddress.getCanonicalHostName());
System.out.println(" getHostName="
+ eachInetAddress.getHostName());
System.out.println(" getHostAddress="
+ eachInetAddress.getHostAddress());
System.out.println(" getAddress=");
byte[] addressByteArray = eachInetAddress.getAddress();
if (addressByteArray != null
&& addressByteArray.length != 0) {
for (int i = 0; i < addressByteArray.length; i++) {
System.out.print(" " + addressByteArray[i] + " ");
}
}
}
System.out.println();
System.out.println();
}
} catch (SocketException e) {
e.printStackTrace();
}
}
下面是打印结果:
getName=lo
getDisplayName=MS TCP Loopback interface
getCanonicalHostName=activate.adobe.com
getHostName=activate.adobe.com
getHostAddress=127.0.0.1
getAddress=
127 0 0 1
为什么loopback的getCanonicalHostName值是activate.adobe.com呢?为什么啊?求解