• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hostname from ip address

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sometimes you can use "ping -a" to resolve the hostname for an IP address.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 147
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 10
Mac PPC Windows XP Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic