BSD Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsBSD Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 3rd, 2003, 04:49 PM
Redtailed's Avatar
Redtailed Redtailed is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Utah, USA
Posts: 83 Redtailed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 31 sec
Reputation Power: 5
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

Reply With Quote
  #2  
Old December 3rd, 2003, 07:28 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,430 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 41 m 55 sec
Reputation Power: 784
man host

If you're a djb fan, dnsname is the way to go
__________________
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

Reply With Quote
  #3  
Old December 3rd, 2003, 07:43 PM
Redtailed's Avatar
Redtailed Redtailed is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Utah, USA
Posts: 83 Redtailed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 31 sec
Reputation Power: 5
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!)

Reply With Quote
  #4  
Old December 4th, 2003, 10:35 AM
Redtailed's Avatar
Redtailed Redtailed is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Utah, USA
Posts: 83 Redtailed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 31 sec
Reputation Power: 5
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.)

Reply With Quote
  #5  
Old December 6th, 2003, 10:48 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,430 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 41 m 55 sec
Reputation Power: 784
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsBSD Help > Reverse IP Lookup by Hosts File


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway