Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't Java's InetAddress class resolving ipv6 addresses to their FQDN?

I'm trying to write a simple program using Java that, given an IP in either version 4 or 6 format, will return its FQDN. The following code works fine when given an ipv4 address, but will only return the given address when an ipv6 address is entered.

InetAddress inet;
try { inet = InetAddress.getByName(theIpAddress); }
catch(UnknownHostException e) { System.out.println("Unknown Host"); return; }

System.out.println(inet.getHostAddress(););
System.out.println(inet.getHostName(););

Whenever I enter an ipv6 getHostName() will only return the same ipv6, even when I know that the ipv6 will resolve to a FQDN. Also, if I enter an ipv6 host name, such as ipv6.google.com, in place of theIpAddress, the exception will occur.

I'm new to this stuff so would appreciate any assistance. Thanks.

like image 545
user561877 Avatar asked Jan 03 '11 23:01

user561877


People also ask

Can InetAddress be used with I need 6?

An IP address is represented by 32-bit or 128-bit unsigned number. InetAddress can handle both IPv4 and IPv6 addresses.

What is InetAddress getByName?

The getByName() method of InetAddress class determines the IP address of a host from the given host's name. If the host name is null, then an InetAddress representing an address of the loopback interface is returned.


1 Answers

The problem was actually the version of Java I was running. Updating Java to 1.6.23, from 1.6.21, allowed ipv6s to resolve to their FQDN.

like image 196
user561877 Avatar answered Nov 14 '22 22:11

user561877