Jayan
Jayan

Reputation: 18459

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

Is it possible to determine if the machine has IPV6 enabled using any Java api?

Upvotes: 0

Views: 651

Answers (2)

Brad Mace
Brad Mace

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

Amir Afghani
Amir Afghani

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

Related Questions