|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
Reverse IP Lookup by Hosts File
I am familiar with how I can enter a host name and IP address into the hosts file on my FreeBSD machine. Once that's done, I can ping the name, and it automatically references the IP address.
Is there a way to do the reverse? I would like to be able to look up, based on an IP address, if there is a reference to that IP address in my hosts file. For example, if I ping "foo" and "foo" is listed in my hosts file as 192.168.0.1, the machine will automatically use that IP address in its ping. If instead I have 192.168.0.1 and I want to know what name, if any, corresponds to it in my hosts file, what command could I use? Thanks for any help on this!
__________________
- Redtailed |
|
#2
|
||||
|
||||
|
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
||||
|
||||
|
Thanks for the suggestion! I wasn't aware of "host" and had been playing for hours with named, resolv.conf, hosts, host.conf, and other aspects of DNS. I'm very much a newbie when it comes to DNS, as you can tell.
The man page for host tells me that I can perform an inverse query by using the IP address. However, I consistently get "host not found" when using IP addresses that do exist in my hosts file. If I use the name found in my hosts file, I get the appropriate IP address. Any suggestions for what I might need to change to get this inverse lookup to work? I admit that the djb stuff looks great, but I'm not experienced enough to install/run it (yet!) |
|
#4
|
||||
|
||||
|
I wasn't able to get this to work on the command line, for example, by typing "host 192.168.0.1" -- however, I was able to get it to work in a PHP script that this functionality ultimately was needed for.
The function gethostbyaddr(string ip address) worked beautifully for pulling names from the hosts file based on ip address. (I suppose this might better have been posted in the PHP forum, but I was first trying to get it to work on the command line, not knowing I'd have a function in PHP to use.) |
|
#5
|
||||
|
||||
|
Yep, that's because the host command doesn't read your /etc/hosts file at all. Instead, it tries to read an actual PTR record from a DNS server.
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > BSD Help > Reverse IP Lookup by Hosts File |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|