Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Whois script help

by Fletch (Chancellor)
on Jan 11, 2005 at 18:41 UTC ( #421361=note: print w/replies, xml ) Need Help??

in reply to Whois script help

If you just want the nameservers you could use Net::DNS and ask for NS records for whatever domain.

Replies are listed 'Best First'.
Re^2: Whois script help
by Kanji (Parson) on Jan 11, 2005 at 19:12 UTC

    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 is, ask the servers where 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.


      Kanji said:

      I second the use of DNS instead of whois.

      but himanh said...

      Basically checking if any of my domains are transferred or still with me.

      So, if himanh asks his DNS server, he will always believe the domain is with him. Just wanted to throw in this advice.

      If you want to make it work, you need to ask a root name server for the delegation information to reach to the name servers. For instance...

      #!/usr/bin/perl -w use strict; use NetAddr::IP; use Net::DNS::Resolver; my $res = new Net::DNS::Resolver; # For domains in CCTLDs, you need to ask instead # and follow the delegation chain. $res->nameservers(NetAddr::IP->new("")->addr); for my $dom (map { chomp; $_ } <DATA>) { my $packet = $res->query($dom, 'NS'); # No answer received... unless ($packet) { warn "No response for $dom\n"; next; } # A DNS answer (response) was received but ... my @answer = $packet->answer; # ... it might not contain real answers ... unless (@answer) { warn "Response packet contains no answer section for $dom\n"; next; } # ... or it might be what I am looking for. for my $s (@answer) { next unless $s->type eq 'NS'; print "$dom: ", $s->nsdname, "\n"; } } __END__

      will answer the right people for the 7 gTLDs. This is only slightly tested and you might need to change the gtld server to use.

      This code should give you something to start playing with...

      Best regards

      -lem, but some call me fokat

        So, if himanh asks his DNS server, he will always believe the domain is with him. Just wanted to throw in this advice.

        Sorry, that was an ommission on my part, but is the reason why I used Net::DNS::Resolver::Recurse instead of the usual Net::DNS::Resolver -- the former starts it's recursive query with the DNS hint servers, which should be the same as the DNS root servers (eg, and are one step up from the gTLD server you use.

        If they're not (because you're running your own root server or using an alternative one), then you can force N:D:R:R to start from a different nameserver with the hints method.

        my @root_ns = map $_ . '', 'a'..'m'; $res->hints(@root_ns);


Re^2: Whois script help
by himanh (Novice) on Jan 11, 2005 at 19:10 UTC
    Hi, I also tried this
    #!/usr/bin/perl use Net::DNS; my $res = Net::DNS::Resolver->new; my $query = $res->query("", "NS"); print "Hi"; if ($query) { foreach $rr (grep { $_->type eq 'NS' } $query->answer) { print $rr->nsdname, "\n"; } } else { warn "query failed: ", $res->errorstring, "\n"; }
    It gives me Internal Server Error. Any help ??

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://421361]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2018-11-21 18:44 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (248 votes). Check out past polls.