Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

host name from an IP  RSS feed

 
tarun matai
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends!
can any one tell me how to get the host name of the target system if i know the IP of the system using a java program
Regards
Tarun
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no reliable way to map from IP address to host name. However, what you can do is post a request to http://www.internic.com/whois.html and parse the response from your Java code.
Eugene.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is called a reverse DNS lookup (since you are mapping the IP to the hostname instead of the other way around) and, as Eugene says, there is no guarantee that a reverse mapping has actually been defined for a given IP. There is also no guarantee that the reverse mapping gives you the same name that you might use for the forward mapping, because multiple names can be mapped to one single IP.The IP address is that of www.javaranch.com, yet the code above outputs "tut.ejip.net". If you paste this in your browser, you'll see that this is indeed the same machine. This won't work for web servers that host multiple sites using virtual hosts!
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!