Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I am trying to resolve names to IP address using a different server and it does not seem to work. I do not get any error but I do not get any output. I am running this on my windows XP using active perl. Here is my code
use Net::Nslookup; open(INFILE, 'os.txt') || die("cannot open file: ".$!); my @lines = <INFILE>; my $switch; foreach $switch(@lines) { my @output = nslookup(host => $switch, server => 10.1.10.42, type => "A"); (my $name, my $ip) = (split /:/, $output[3]); print "$ip\n"; } close INFILE;
Any help would be appreciated.

Edited by planetscape - fixed code tags

Replies are listed 'Best First'.
Re: Nslookup using a different DNS server
by johnnywang (Priest) on Nov 14, 2005 at 20:06 UTC
    I've been using Net::DNS::Resolver, which you can put the dns server name in the constructor. Something like the following:
    use Net::DNS::Resolver; my $nameserver = "10.1.10.42"; my $resolver = Net::DNS::Resolver->new( nameservers=>[$nameserver], recurse =>1, debug =>0, ); my @addresses = (); my $host ='yahoo.com'; my $query = $resolver->search($host); if ($query){ foreach my $rr ($query->answer) { next unless $rr->type eq "A"; push @addresses,$rr->address if $rr->address =~/^[\d\.]+$/; } } else { warn "query failed: ", $resolver->errorstring, "\n"; }
Re: Nslookup using a different DNS server
by japhy (Canon) on Nov 14, 2005 at 20:30 UTC
    Your specific problem is that your server needs to be a string, '10.1.10.42', not a v-string (or whatever the hell they're called now) 10.1.10.42 which represents chr(10).chr(1).char(10).chr(42).

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart