Net::DNS-> About setting more than one nameserver to lookup.

E

eloelo

I want to use four nameserver to look up a domain's IP.
But why the code below can lookup domain's IP only using one nameserver.


#!/usr/bin/perl
use Net::DNS;
@ns=('222.33.11.2','223.55.4.3','223.55.4.2','223.55.4.7');

for($i=0;$i<4;$i++)
{
my $res = Net::DNS::Resolver->new;
$res->nameservers($ns);
my $query = $res->search("www.bdchina.com");

if ($query)
{
foreach my $rr ($query->answer)
{
next unless $rr->type eq "A";
print "$ns---->",$rr->address, "\n";
}
}
else
{
warn "$ns---->query failed: ", $res->errorstring, "\n";
}
}
 
M

Michael Fuhr

eloelo said:
I want to use four nameserver to look up a domain's IP.
But why the code below can lookup domain's IP only using one nameserver.

Add "use warnings" to your script and let Perl tell you. Many
programmers consider "use strict" to be good practice as well.
#!/usr/bin/perl
use Net::DNS;
@ns=('222.33.11.2','223.55.4.3','223.55.4.2','223.55.4.7');

for($i=0;$i<4;$i++)
{
my $res = Net::DNS::Resolver->new;
$res->nameservers($ns);
my $query = $res->search("www.bdchina.com");

if ($query)
{
foreach my $rr ($query->answer)
{
next unless $rr->type eq "A";
print "$ns---->",$rr->address, "\n";
}
}
else
{
warn "$ns---->query failed: ", $res->errorstring, "\n";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top