This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes General Computing and the fly likes hostname from ip address Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » General Computing
Bookmark "hostname from ip address" Watch "hostname from ip address" New topic
Author

hostname from ip address

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Hi,

I recently started supporting an application.
We often get IP address in error logs something like: Couldn't connect to 1.2.3.4, Time Out. We've many systems (servers) in whole application infrastructure.
There is no document which says that this ip belongs to this server, probably because ips are not static or servers are being referred by their names to no one cared for ips.

Is there anyway to determine hostname from ip address?
I checked some websites but our ips are "unknown" to them, may be some firewall thing.

Any help would be appreciated.

Thanks.


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

ankur rathi wrote:
Is there anyway to determine hostname from ip address?
I checked some websites but our ips are "unknown" to them, may be some firewall thing.


Don't your company have a sys admin? Who you can ask this stuff? Static addresses should hopefully be documented somewhere. For dynamic addresses, you should be able to determine the switch(es) from the subnet, which can get you to a location. You can also probably figure out other information from the DHCP logs, like the MAC address... and then, hopefully, it is documented somewhere.

But as mentioned, you'll need the help of your sys admin for this stuff.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5835
    
    7

Sometimes you can use "ping -a" to resolve the hostname for an IP address.


JBoss In Action
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Peter Johnson wrote:Sometimes you can use "ping -a" to resolve the hostname for an IP address.


Yes, ping command does give hostname for an ip address but I can't access those ips from my local system so I get timeout when I ping them.
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
Rathi, You can use below small java program to get host name from IP.

try
{
java.net.InetAddress inetAdd = java.net.InetAddress.getByName("206.190.60.37");
//127.0.0.1 is loop back address
System.out.println ("Hostname is: " + inetAdd.getHostName());
}
catch(java.net.UnknownHostException uhe)
{
//handle exception
}


-Sunil
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5835
    
    7

but I can't access those ips from my local system

Then it is impossible to find out the host names in the usual manner (using network commands, or the code xsunil provided). You will either have to ask your system admin, or if the machines are maintained in some directory service, perhaps an LDAP query will yield the information.
aaliyah dcunha
Greenhorn

Joined: May 31, 2011
Posts: 10

xsunil kumar wrote:Rathi, You can use below small java program to get host name from IP.

try
{
java.net.InetAddress inetAdd = java.net.InetAddress.getByName("206.190.60.37");
//127.0.0.1 is loop back address
System.out.println ("Hostname is: " + inetAdd.getHostName());
}
catch(java.net.UnknownHostException uhe)
{
//handle exception
}


-Sunil


Thanks Sunil, i also try some thing like this. but i appreciate you efforts. i will also use this.


http://www.chevroletbeat.net/
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Peter Johnson wrote:
but I can't access those ips from my local system

Then it is impossible to find out the host names in the usual manner (using network commands, or the code xsunil provided).

Are you sure? A normal reverse DNS lookup should give you the results even if you can't access the particular IP addresses. This assumes, of course, that the IP addresses in question actually resolve to a hostname, and that the reverse DNS is configured properly.

Note: folks upthread are talking about using PING, in a slightly incorrect way. Ping is a network test which is handy, but it is not necessary. Ping is a separate protocol and is often blocked by firewalls, etc. You do *not* need to be able to ping a host to be able to talk to it via TCP/IP

R sona
Greenhorn

Joined: May 09, 2011
Posts: 3
Pat Farrell wrote:
Peter Johnson wrote:
but I can't access those ips from my local system

Then it is impossible to find out the host names in the usual manner (using network commands, or the code xsunil provided).

Are you sure? A normal reverse DNS lookup should give you the results even if you can't access the particular IP addresses. This assumes, of course, that the IP addresses in question actually resolve to a hostname, and that the reverse DNS is configured properly.

Note: folks upthread are talking about using PING, in a slightly incorrect way. Ping is a network test which is handy, but it is not necessary. Ping is a separate protocol and is often blocked by firewalls, etc. You do *not* need to be able to ping a host to be able to talk to it via TCP/IP



NBTSTAT -A 10.10.10.10 will work on windows.
nmblookup -A 10.10.10.10 is for linux.

Thanks,
Rahul
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Much of this thread assumes that there is a 1-1 relationship between IP address and domain name. This is not the case. My fixed IP address has 4 domain names so given the IP address which domain name should be returned in any lookup?


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

James Sabre wrote:Much of this thread assumes that there is a 1-1 relationship between IP address and domain name. This is not the case. My fixed IP address has 4 domain names so given the IP address which domain name should be returned in any lookup?

No, all of the thread.
The standard method of getting a reverse DNS returns one value. Its a feature.
 
GeeCON Prague 2014
 
subject: hostname from ip address