开发者

java - how to find if the machine has Ipv6 interface?

Is it possible to determine if the machin开发者_开发技巧e has IPV6 enabled using any Java api?


Look at the NetworkInterface class. It has methods for getting all the machine's network interfaces including virtual ones. You could look at the InetAddress for each interface and use inetAddress.getAddress().length to check the number of bytes in the IP to distinguish between IPv4 and IPv6.


InetAddress a = InetAddress.getByName(“www.sun.com”);
if (a instanceof Inet6Address) {
    Inet6Address a2 = (Inet6Address) a;
    if (a2.isIPv4CompatibleAddress()) {
        ...
    } if (
        a2.isLinkLocalAddress()) {
        ...
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜