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()) {
...
}
}
精彩评论