Net::DNS



Hi,

I need to check through a database of just over 19000 domains to check from an authoritative server of the root domain which nameservers are used by these domains.

so for host.com I want to get the nameserver of host.com from an SOA of com for example, l.gtld-servers.net

I've Googled about and put together this routine partially from the Net::DNS site and from the O'Reilly bind book.

This works great.. but it takes 68 minutes.. Am I doing something crazy here or is this normal. I'm not 100% sure if I'm doing it right and I'd appreciate you having a look. Note that this is something I put together to get it working and I will clean it up and have better error checking etc. I'm more interested in knowing if I'm doing the Net::DNS thing corretly. Thanks in advance.

This is the routine, see how I'm calling it below.

sub searchit {
# Fix and handle errors so that it does not fall over.
my ($domain, $nameserv) = @_;

my $res = new Net::DNS::Resolver;
$res->defnames(0);
$res->retry(1);
$res->tcp_timeout(15);
$res->udp_timeout(15);
$res->persistent_tcp(1);
$res->persistent_udp(1);

my $ns_req = $res->query($domain, "NS");

unless (defined($ns_req) and ($ns_req->header->ancount > 0)) {
return $res->errorstring;
}

my @nameservers = grep { $_->type eq "NS" } $ns_req->answer;

$| = 1;
$res->recurse(0);
if (defined $nameserv) {
$res->nameservers($nameserv);
}

my $new_nameserv;
foreach my $nsrr (@nameservers) {
my $ns = $nsrr->nsdname;

unless ($res->nameservers($ns)) {
return $res->errorstring;
}
$new_nameserv = $ns;
last;

}
return $new_nameserv;
}

I have a loaded array of the domain names and I run the above like this:


for $domain (@domain_array) {
$root_dom = $domain;
$root_dom =~ s/^.*\.//;
# I get the root domain and only look it up the once..
if (defined $dom_auth{$root_dom}) {
$answer = searchit($domain,$dom_auth{$root_dom});
} else {
# User my resolv.conf's nameserver for the top domain NS
$answer = searchit($root_dom,"");
$dom_auth{$root_dom} = $answer;
$answer = searchit($domain,$dom_auth{$root_dom});
}
printf ("%-35s %-5s %-25s %-25s\n", $domain,$root_dom,$dom_auth{$root_dom},$answer);
}
--
_ Jerry Rocteur MACosX@xxxxxxxxxx
_|_|_ http://www.rocteur.cc
(0 0) MSN macosx@xxxxxxxxxx
ooO--(_)--Ooo Jabber jerry@xxxxxxxxxxxxxxxxx
_________________________________________________
[06:23:57 rocteur.cc /Users/jerry]
.