Best way to check if IPv6 is available


What is the best way to check if IPv6 is available on the currient android phone?

My currient idea is to use <a href="http://developer.android.com/reference/java/net/NetworkInterface.html" rel="nofollow">NetworkInterface</a> and to enumerate via <a href="http://developer.android.com/reference/java/net/NetworkInterface.html#getNetworkInterfaces%28%29" rel="nofollow">NetworkInterface.getNetworkInterfaces()</a> but this seems to be too complicated.

Is there a simpler way?


I don't know of a simpler way than using <a href="http://docs.oracle.com/javase/6/docs/api/java/net/NetworkInterface.html" rel="nofollow">NetworkInterface</a> if you need to check all of the interfaces, but it shouldn't be that bad:

for(NetworkInterface netInt: NetworkInterface.getNetworkInterfaces()){ for(InterfaceAddress address: netInt.getInterfaceAddresses()){ if(address.getAddress() instanceof Inet6Address){ // found IPv6 address // do any other validation of address you may need here } } }

if you know the address you want to check you can skip using NetworkInterface and check the specific InetAddress by calling one of InetAddress's static <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/net/InetAddress.html#getByAddress%28byte%5B%5D%29" rel="nofollow">getBy...()</a> methods and check whether that is an instance of Inet6Address.


boolean isIPV6 = false; Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface ni = networkInterfaces.nextElement(); for (InterfaceAddress addr : ni.getInterfaceAddresses()) { if (addr.getAddress() instanceof Inet6Address) { isIPV6 = true; } } }


  • JavaScript: when I pass array from iframe function the array lose his type!
  • How to deal with errors in the Dropbox java API
  • HTTP interceptor getting status 0 on failed request using Angular 4
  • Can not set gravity with setGravity vertically programatically. Is this an android bug or feature?
  • Three.JS- Detecting intersection in Collada (Ray Casting)
  • How to handle a session timeout exception (with MVP Places and Activities)?
  • Sonar Violation: Dodgy - Write to static field from instance method
  • Magento Mass Action, grid does not update
  • laravel how to prefix all json responses to protect against json injection
  • Why functions are objects in javascript?
  • Post a KeyEvent to the focused component
  • How to get the class type for which a collection object is created using reflection
  • Dependent collection duplicates when I save entity
  • Extending an Array properly, keeping the instance of subclass
  • Symfony dependency injection in twig extension
  • java.lang.OutOfMemoryError: Java heap space for 100000 records
  • How to check if object is an jQuery Xhr object
  • Laravel error handling, get_class vs instanceof
  • Dynamic cast to generic type in Java
  • Strange XML indentation
  • How to take advantage of kernel.terminate inside an event listener
  • PHP: Overriding parent methods with __call
  • Best Way to create configuration file(config.php) php
  • Does passing a struct into an interface field allocate?
  • ArrayList in C#
  • How does “boxing” work in .NET?
  • Variant of defaultdict for assigning value only once
  • How to prevent TreeItem selection?
  • xul/xpcom copy image from string to clipboard
  • Best Datagrid for Bootstrap/jQuery?
  • WebApp in AppServices vs CloudService
  • How to get Fully qualified domain name in unix
  • Symfony2 - Doctrine - no changeset in post update
  • bad substitution shell- trying to use variable as name of array
  • Assign variable to the value in HTML
  • Bad request using file_get_contents for PUT request in PHP
  • D3 nodes and links from JSON with nested arrays of children
  • Android Studio and gradle
  • SQL merge duplicate rows and join values that are different
  • MATLAB: Piecewise function in curve fitting toolbox using fittype