http://www.perlmonks.org?node_id=421379


in reply to Re: Whois script help
in thread Whois script help

I second the use of DNS instead of whois.

Even with modules, whois output can be a pain to parse into something consistent for all TLDs, something made trickier by the number of registrars who limit the number of whois queries you can do per day (eg, .tv allows 20/day per IP, which makes life interesting when you have 21 .tv domains :-).

DNS doesn't have those limitations, but is equally capable of telling whether you should still be authoritative for a hostname by walking it's heirachy (eg, ask the root servers where .org is, ask the .org servers where pm.org is, ask the pm.org servers where www.pm.org is, etc.).

Something like...

#!/usr/bin/perl use strict; use warnings; use Net::DNS::Resolver::Recurse; my $host = shift or die "Usage: $0 hostname\n"; my $res = Net::DNS::Resolver::Recurse->new; my $ans = $res->query_dorecursion($host, 'NS'); my @ns; foreach my $ns ($ans->additional) { push @ns, sprintf " %s (%s)\n", $ns->name, # hostname $ns->rdatastr; # ip } print "$host has ", scalar(@ns), " servers:-\n", @ns;

...should do the trick, if only to reduce the list of domains you don't need to whois.

    --k.