LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   how do i perform an reverse dns lookup? (https://www.linuxquestions.org/questions/linux-networking-3/how-do-i-perform-an-reverse-dns-lookup-644070/)

HyperTrey 05-22-2008 01:09 PM

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???

nacio 05-22-2008 01:43 PM

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 :)

HyperTrey 05-22-2008 02:13 PM

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?

nacio 05-22-2008 02:34 PM

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`;


HyperTrey 05-23-2008 08:48 AM

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}\'");


All times are GMT -5. The time now is 12:20 PM.