LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices



Reply
 
Search this Thread
Old 08-25-2008, 03:03 PM   #1
Geneset
Member
 
Registered: Jan 2007
Location: Athlone, ROI
Distribution: Ubuntu Hardy Desktop, Solaris 10, Workstation 2008 x64
Posts: 75

Rep: Reputation: 16
Question Lookup hostname from IP address


Hi guys
I'm writing a script to parse the ip table from my router but I'm up against a brick wall of how to easily convert from an ip address to a hostname.

whois creates alot of output and is not standardised really, I'm just simply looking to get from xxx.xx.xx.xx to computer.domain.tld

any ideas?

Cheers
 
Old 08-25-2008, 03:07 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 31
Try the 'nslookup' command. It should give you the human readable hostname as part of its output as long as your nameserver is setup correctly.
 
Old 08-25-2008, 03:07 PM   #3
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 476
Blog Entries: 121

Rep: Reputation: 74
Quote:
Originally Posted by Geneset View Post
Hi guys
I'm writing a script to parse the ip table from my router but I'm up against a brick wall of how to easily convert from an ip address to a hostname.

whois creates alot of output and is not standardised really, I'm just simply looking to get from xxx.xx.xx.xx to computer.domain.tld

any ideas?

Cheers
host xxx.xxx.xxx.xxx | cut -d' ' -f5
 
Old 08-25-2008, 03:34 PM   #4
Geneset
Member
 
Registered: Jan 2007
Location: Athlone, ROI
Distribution: Ubuntu Hardy Desktop, Solaris 10, Workstation 2008 x64
Posts: 75

Original Poster
Rep: Reputation: 16
Talking

Thanks rocket thats a charmer.

Had just found rhost in the jdresolve package but its far too slow.
thats perfect.
Much appreciated, but can you guys cast ur mind to this also?
 
Old 08-25-2008, 04:01 PM   #5
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 69
Code:
$ dig +short -x <ip address>
works too. Don't use nslookup for anything, it's deprecated and due to be replaced. Learn to use dig instead.

PS Be aware that you'll get an empty string if there is no PTR record for the IP address, so you script has to know that an empty response from dig means that there's no PTR for the IP.

Last edited by chort; 08-25-2008 at 04:03 PM.
 
Old 08-26-2008, 06:03 AM   #6
Geneset
Member
 
Registered: Jan 2007
Location: Athlone, ROI
Distribution: Ubuntu Hardy Desktop, Solaris 10, Workstation 2008 x64
Posts: 75

Original Poster
Rep: Reputation: 16
Cheers, using dig, works great. Wish more people had stuff like this documented online, i spent about 30 minutes googling "lookup hostname from ip unix" "reverse dns unix ip hostname".... and so the list of polymorphic combinations went on....

ALWAYS DEAL WITH A PERSON, lol <SOLVED>
 
  


Reply

Tags
hostname, ip, lookup


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hostname lookup failure chandrait2004 Linux - Newbie 3 06-23-2011 04:23 PM
DHCP seems to set hostname = Mac address, doesn't reverse lookup techsimian Linux - Networking 4 08-15-2006 05:11 PM
Adding hostname and IP address to DNS for sendmail ip lookup Simon_T Linux - Networking 1 06-04-2006 08:30 AM
Apache log hostname lookup program ? Carlee Linux - Software 1 01-29-2005 06:40 PM
Odd hostname lookup problem max_sipos Linux - Networking 3 11-15-2004 12:29 PM


All times are GMT -5. The time now is 11:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration