Tuesday, April 9, 2013

HOW TO CHECK IF IPv6 is Used

Hi,

You might have came across lot of issues due to IPV6 enabled on your machine/server and even disabling IPV6 doesn't put an end to your issue. Then here is a java code that you can run to confirm if IPV6 is disabled or not:

import java.net.*;
import java.util.*;


public class IPV4Only {
 public static void main(String[] args) throws Exception {

    boolean b=true;
     Enumeration nifs = NetworkInterface.getNetworkInterfaces();
     while (nifs.hasMoreElements()) {
         NetworkInterface      nif = nifs.nextElement();
         Enumeration addrs = nif.getInetAddresses();
         while (addrs.hasMoreElements()) {
             InetAddress hostAddr = addrs.nextElement();
             if ( hostAddr instanceof Inet6Address ){
                b=false;
                 System.out.println("NetworkInterfaceV6List failed - found IPv6 address " + hostAddr.getHostAddress() );
             }
         }
     }
    if (b) {
        System.out.println("No IPv6 detected");
    } else {
        System.out.println("Detect IPv6 interfaces - use java property java.net.preferIPv4Stack=true ");
    }
 }
}


Reference: