IP number to IP name/domain name

Hi,
I am using the following code to retrieve the IP name from a given IP number:

InetAddress iAddress = InetAddress.getByName("64.68.82.173");
String ipName = iAddress.getCanonicalHostName();

But it is returning only the id address which is not true, it is suppose to return "crawler14.googlebot.com" (this is what I am getting when I tired from other online IP host names finders, for ex: http://www.hcidata.co.uk/host2ip.htm

Any idea? I have also tried other related methods for example: getHostAddress,getAddress,

Thanks
javagiripAsked:
Who is Participating?
 
DrWarezzCommented:
0
 
BreadstickCommented:
Is this what you're looking for?

iAddress().getHostName();
0
 
BreadstickCommented:
Whoops... sorry, nevermind.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
javagiripAuthor Commented:

But iAddress().getHostName() is also returning "64.68.82.173" not the host name/domain name, I need to get something like "crawler14.googlebot.com". Did you test it? what is it returning to you?

Thanks
0
 
BreadstickCommented:
Yeah, I tried it.  The following works:
---
        byte[] ipAddr = new byte[]{127, 0, 0, 1};

        InetAddress addr = InetAddress.getByAddress(ipAddr);

        System.out.println(addr.getHostAddress());
        System.out.println(addr.getHostName());
---

I couldn't get it working with 64.68.82.173 because I couldn't put 173 into the byte array, because the largest value a byte can hold is 127.  I'm not sure how to get around this...

Experts?
0
 
javagiripAuthor Commented:
Thank, Good try. Any one else know how to get the hostname from an IP address? thanks
0
 
ThummalaRaghuveerCommented:
as byte in java is signed it cannot hold more than 127.

Work around for this is just to cast it to byte say like

byte[] ipAddr = new byte[]{(byte)128, 82, 5, (byte)244};

This works
0
 
BreadstickCommented:
> Here you go:
http://www.javaalmanac.com/egs/java.net/GetHostname.html

I found that link too, but it doesn't work outside of localhost.  Try it.
0
 
DrWarezzCommented:
Oh, I've never had that problem before. Okay -- thanks Breadstick :)
[r.D]
0
 
javagiripAuthor Commented:
Thanks :)
0
 
DrWarezzCommented:
ta :)
[r.D]
0
 
BreadstickCommented:
Where you able to get that to work with the googlebot?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.