Reputation: 18459
Is it possible to determine if the machine has IPV6 enabled using any Java api?
Upvotes: 0
Views: 651
Reputation: 27886
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.
Upvotes: 2
Reputation: 38531
InetAddress a = InetAddress.getByName(“www.sun.com”);
if (a instanceof Inet6Address) {
Inet6Address a2 = (Inet6Address) a;
if (a2.isIPv4CompatibleAddress()) {
...
} if (
a2.isLinkLocalAddress()) {
...
}
}
Upvotes: 1