LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-22-2008, 01:09 PM   #1
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Rep: Reputation: 15
Question how do i perform an reverse dns lookup?


I am attempting to try to write a perl script that will print stats to an email, now I need to do a reverse dns lookup because the computers are stored in the log file as IP addresses. The powers to be want the PC name not the address. I know the commands to do it, host, nslookup and dig. host and nslookup seem to have the most promise. How would i word either of those commands with options to get just the pc name and not the other info???
 
Old 05-22-2008, 01:43 PM   #2
nacio
LQ Newbie
 
Registered: Mar 2007
Location: Italy
Distribution: Debian
Posts: 18

Rep: Reputation: 0
I don't know about an option that will cause host or nslookup to give you what you want, but you may try this:

host <ip> | awk '{print $NF}' | head -c -2

You may also implement this string manipulation in perl instead of using pipes
 
Old 05-22-2008, 02:13 PM   #3
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Original Poster
Rep: Reputation: 15
Question

Code:
 host <ip> | awk '{print $NF}'
that worked out for what i need actually, the next thing is in perl itself. I cant figure why this line of code doesn't work, I have used it in the under different situation in another piece of script.

what i have is the IP address from a CSV log file and it is in the form of \\1.2.3.4 and It is in the array it is $a[6]

Code:
$a[6] = (split(/\\/, $a[6]));
that is what i have it ends up setting $a[6] to 3 only. What did i mess up there?


and to set a variable with the system command would be:

Code:
$host = "system 'host $ip | awk '{print $NF}''";
??? or which is it?

Last edited by HyperTrey; 05-22-2008 at 02:27 PM.
 
Old 05-22-2008, 02:34 PM   #4
nacio
LQ Newbie
 
Registered: Mar 2007
Location: Italy
Distribution: Debian
Posts: 18

Rep: Reputation: 0
The following code appears to work

Code:
$a[6] = "\\\\1.2.3.4";
($b, $a[6]) = (split(/\\\\/, $a[6]));

$ip = $a[6];
$cmd = "host $ip | awk \'{print $NF}\'";
$host = `$cmd`;

Last edited by nacio; 05-22-2008 at 02:39 PM.
 
Old 05-23-2008, 08:48 AM   #5
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Original Poster
Rep: Reputation: 15
Code:
($pcname) = (split(/\\/, $pcname))[2];
that worked for splitting the the \\ off. I forgot to set it to another variable and the forgot the number of the array it creates of the split.

however running this command doesn't work correctly in perl however it does in the command. There has to be a better way to run a mutli command line in perl without setting it to another variable.

here is the code that doesn't work, the first part works however it seem to ignore the | awk part. How do i get it to not ingore it? :

Code:
system("host $ip | awk \'{print $NF}\'");
 
  


Reply


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
reverse DNS lookup mimithebrain Linux - Networking 5 06-08-2006 08:28 AM
DNS Reverse lookup problem pazvant Linux - Networking 3 10-10-2005 06:36 AM
DNS reverse lookup problems... pdmackenzie Linux - Networking 2 09-19-2003 05:00 PM
Reverse DNS lookup, or any way to contact an IP.. MasterC Linux - Networking 6 02-21-2003 03:34 AM
reverse DNS lookup phil1076 Linux - General 1 01-22-2002 03:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:25 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration