• Post Reply Bookmark Topic Watch Topic
  • New Topic

InetAddres - Can't retrieve some FQDM from IP addresses  RSS feed

 
mor sellam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to retrieve a FQDM from IP address by using InetAddress without success

my JAVA program:

public static void main(String[] args) {

String result = "";

String ipAddress = new IPAddress(args[0]);

try {
result = Inet6Address.getByName(ipAddress).getHostName();
} catch (UnknownHostException e) {
System.out.println("Error in DNSLocator#getNameToResolve");
}

System.out.println("IP- "+ipAddress +" NAME- "+result);

}

For the input: 125.56.199.115
I receive: IP- 125.56.199.115 NAME- 125.56.199.115

--------------------------------------------------------------

Using ping -a command:

Pinging a125-56.199-115.deploy.akamaitechnologies.com [125.56.199.115] with 32 bytes of data:
Reply from 125.56.199.115: bytes=32 time=409ms TTL=45
Reply from 125.56.199.115: bytes=32 time=397ms TTL=45

--------------------------------------------------------------

Using nslookup command :

nslookup 125.56.199.115
Server: 172.17.0.10
Address: 172.17.0.10#53

Non-authoritative answer:
115.199.56.125.in-addr.arpa name = a125-56.199-115.deploy.akamaitechnologies.com

--------------------------------------------------------------

What can be the cause? how Java resolve ip to name? What is the difference between Java and nslookup/ping??

I tried to add -Dsun.net.spi.nameservice.provider.1=dns,sun
but it's still not works.

Thanks.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A colleague of mine happened to run into this issue today, and I remembered some behaviour of InetAddress I recently discovered.

When you call getByName with an IP address as the argument (either IPv4 or IPv6), the method does not check the DNS. It just creates a new Inet4Address or Inet6Address with the IP address as both the address and the hostname.

The solution is pretty simple fortunately: use getCanonicalHostName() instead of getHostName().
 
mor sellam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I tried to change getHostName() to getCanonicalHostName()
But I still receive IP instead of name


IP- 125.56.199.115 Name- 125.56.199.115

But other IPs works, such as

IP 23.5.165.18 Name- a23-5-165-18.deploy.static.akamaitechnologies.com

These addresses accessible and you can also try to resolve this IPs
Do you have another idea of what could be the reason?

Thanks
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!