1

上面的 JDK 1.5 可以很好地返回 IPV6 地址。但是 JDK1.4.2 只返回 IPV4 地址。操作系统是 Windows XP 和 Windows 7。有人设法在 JDK 1.4.2 上获得 IPV6 地址吗?

    NetworkInterface iface = null;
    for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces
            .hasMoreElements();) {
        iface = (NetworkInterface) ifaces.nextElement();

        InetAddress ia = null;
        for (Enumeration ips = iface.getInetAddresses(); ips
                .hasMoreElements();) {
            ia = (InetAddress) ips.nextElement();
            System.out.println(ia.getHostName());
        }

    }

我怀疑 java.net.InetAddressImplFactory 中有这个本机代码。

private static native boolean isIPv6Supported();

由于JDK1.4.2是很久以前开发的,可能不兼容Windows的原生库来获取IPV6地址。这个对吗?

4

0 回答 0