title: Return IPv6 in Java
body: <p>Is there a way in Java to tell it to return IPv6 only?  I've tried everything and can't get it to work.</p>
  
  <pre><code>try
      {
          InetAddress inet = InetAddress.getByName(hostName);
  
          boolean status = inet.isReachable(5000);
  
          if (status)
          {
              System.out.println(inet.getCanonicalHostName() + " Host Reached\t" + java.net.Inet6Address.getByName(hostName).getHostAddress());
          }
          else
          {
              System.out.println(inet.getCanonicalHostName() + " Host Unreachable");
          }
  
      }
      catch (UnknownHostException e)
      {
          System.err.println("Host does not exists");
      }
      catch (IOException e)
      {
          System.err.println("Error in reaching the Host");
      }
  </code></pre>
  
  <p>The line I use to try to return IPv6 only:</p>
  
  <pre><code>System.out.println(inet.getCanonicalHostName() + " Host Reached\t" + java.net.Inet6Address.getByName(hostName).getHostAddress());
  </code></pre>
  
  <p>This keeps returning IPv4.  Anyone have any idea of why its doing this?</p>