获取IPV6时的错误是Java java.net.NetworkInterface

我尝试使用以下方法获取IPV6地址:

Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
  NetworkInterface iface = interfaces.nextElement();
  if (iface.isLoopback() && !includeLoopback || !iface.isUp()) {
    continue;
  }
  Enumeration<InetAddress> addresses = iface.getInetAddresses();
  while (addresses.hasMoreElements()) {
    InetAddress addr = addresses.nextElement();
    inetAddresses.add(addr.getHostAddress());
  }
}

这打印:fe80:0:0:0:250:56ff:fe85:5cb2%eth0

当我做ifconfig时,它给出了以下作为ipv6地址 - fe80 :: 250:56ff:fe85:5cb2 / 64

我在哪里错过了?帮助将不胜感激 . 谢谢!

回答(1)

2 years ago

IPV6标准说:

:: equals:0:0:0: