Can anyone tell me how to perform a dns lookup using perl?
I am using nslookup, what is a better way to do this?


Here is a snippet of my code :


#!/opt/local/bin/perl

%dns = &NSLOOKUP($ARGV[0]);
print "\n ip = $dns{Address}      host =  $dns{Name}\n\n";

#-------------------------------------------

sub NSLOOKUP {
   ($ip) = @_;
   %mydns = ();

   #... query dns, replace newline with #, remove multiple spaces
   $foo = `nslookup $ip`; $foo =~ s/\n/\#/g; $foo =~ s/\s//g;

   #... create array with # as the splitter
   split /#+/, $foo;

   #... see if name or ip is valid
   if ( $#_ > 0 && $foo =~ /$ip/i ) {
      foreach $item (@_) {
         @foo = split /:+/, $item;
         $mydns{$foo[0]} = $foo[1];
      }
   } else {
      if ( $ip =~ /\d+(\.\d+){3}/ ) {
         $mydns{Name} = "NOT FOUND IN DNS";
         $mydns{Address} = "$ip";
      } else {
         $mydns{Name} = "$ip";
         $mydns{Address} = "$NOT FOUND IN DNS";
      }
   }
   %mydns;  #I love hashes, so return the results in a hash table
}
#------------------------------END OF
CODE--------------------------------------


nslookup 172.20.2.68  produces the following output:

Server:  tiger1.aaahawk.com
Address:  255.255.255.1

Name:    bingo1.aaahawk.com
Address:  172.20.2.68

---------------------------------------------------------


So when I run my script, I obtain:

 ip = 172.20.2.68      host =  bingo1.aaahawk.com

which is fine.  The problem is when the number of ips gets large (1000),
then my script performs 1000 nslookups.  So I am looking for a better
alternative.  That is if I could do a zone transfer to an output file (one
time operation), then do a grep on the ip for the name.

Is there a way to do this?  If so what is it.  I have tried dig and host,
but nslookup seems to produce the desired results.

__________________


__________________

William Ampeh (x3939)
Federal Reserve Board


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to