in reply to Adding an nslookup to a log script
Have a look at gethostbyaddr. This will take the address you want to look up as a packed binary representation. If @addr contains your four parts then I think $packed_addr=pack('C4', @addr) will get you the version you need. It also needs the address type, that is 4 for TCP/IP. It returns an array, the first element of which is what you want. Here is a one liner that should get your started, just feed it dotted format IPs on STDIN.
perl -ple'chomp;@add=split/\./;$pkd=pack('C4',@add);($name)=(gethostby +addr $pkd,4);$_.=" > $name"'
As for looping again, why not do the address lookup when you are in the output loop ?
Cheers,
R.
|
|---|