Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hostname from ip address

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20992
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes you can use "ping -a" to resolve the hostname for an IP address.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
Chrome Mac PPC Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic