Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

IP number to IP name/domain name

Posted on 2004-10-22
12
Medium Priority
?
243 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:javagirip
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 2

Expert Comment

by:Breadstick
ID: 12383053
Is this what you're looking for?

iAddress().getHostName();
0
 
LVL 2

Expert Comment

by:Breadstick
ID: 12383088
Whoops... sorry, nevermind.
0
 

Author Comment

by:javagirip
ID: 12383092

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

by:Breadstick
ID: 12383224
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
 

Author Comment

by:javagirip
ID: 12383298
Thank, Good try. Any one else know how to get the hostname from an IP address? thanks
0
 
LVL 2

Expert Comment

by:ThummalaRaghuveer
ID: 12383908
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
 
LVL 9

Accepted Solution

by:
DrWarezz earned 200 total points
ID: 12385617
0
 
LVL 2

Expert Comment

by:Breadstick
ID: 12388344
> 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
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12388353
Oh, I've never had that problem before. Okay -- thanks Breadstick :)
[r.D]
0
 

Author Comment

by:javagirip
ID: 12410649
Thanks :)
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12410829
ta :)
[r.D]
0
 
LVL 2

Expert Comment

by:Breadstick
ID: 12411043
Where you able to get that to work with the googlebot?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question