Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Whois script help

by himanh (Novice)
on Jan 11, 2005 at 17:03 UTC ( [id://421334]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I am the newest user in the PERL world. I hope that i will learn somethings from the Monks. My problem is simple, i have a list of domains in a text file on my server and i want to know each domains nameservers. Basically checking if any of my domains are transferred or still with me. I started with a small script i found on PM as below ::
#!/usr/local/bin/perl use Net::Whois::IP qw(whoisip_query); use strict; my $ip = "www.yahoo.com"; my $tt = 0; my @tyy; my $response = whoisip_query($ip); foreach (sort keys(%{$response}) ) { print "$_ $response->{$_} \n"; $tyy[$tt] = "$_ $response->{$_} \n"; $tt++; }
I thought this will give me all the WHOIS data of yahoo.com but it came with this ::
"The specified CGI application misbehaved by not returning a complete +set of HTTP headers."
Can someone tell me why it is happening ? And if someone can help me with my actual problem of getting nameservers of domains that are in the text file with one domain in each line. Thanks.

Replies are listed 'Best First'.
Re: Whois script help
by Tanktalus (Canon) on Jan 11, 2005 at 17:14 UTC

    www.yahoo.com isn't an IP. It's a name. Convert it to an IP first. For example, just changing "www.yahoo.com" to "216.109.118.67" made the script work here.

    There are many ways to get perl to convert the name to a number - although in this case I just ran "host www.yahoo.com" at the command prompt. ;-)

    (hint: I use Net::hostent)

Re: Whois script help
by Zaxo (Archbishop) on Jan 11, 2005 at 17:17 UTC
Re: Whois script help
by gellyfish (Monsignor) on Jan 11, 2005 at 17:19 UTC

    Are you running this program under the CGI? If so then yes you will get that message because you are not outputting any headers at all. You should first try to run this from the command line to see if it works, then if you want to run it as a CGI program you should add:

    print "Content-Type: text/plain\n\n";
    into the program somewhere before entering the foreach loop.

    Of course Net::Whois::IP is not the module that you want at all because that module is designed to query for WHOIS records for IP blocks - you probably want to look at either Net::Whois or Net::Whois::Raw. For example:

    #!/usr/bin/perl -wT + use strict; use CGI qw(:standard); use Net::Whois::Raw qw(whois); + print header("text/plain"); print whois('yahoo.com');

    /J\

Re: Whois script help
by mrborisguy (Hermit) on Jan 11, 2005 at 18:07 UTC
    try Net::Whois::ARIN
      Can you please provide a small example if i want to know the nameservers of the site www.yahoo.com using this module ? I m new so i will need some helping hand. Thanks.
Re: Whois script help
by Fletch (Bishop) on Jan 11, 2005 at 18:41 UTC

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

      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.


        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 root-servers.net instead # and follow the delegation chain. $res->nameservers(NetAddr::IP->new("g.gtld-servers.net")->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__ google.com yahoo.com aol.com

        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

      Hi, I also tried this
      #!/usr/bin/perl use Net::DNS; my $res = Net::DNS::Resolver->new; my $query = $res->query("yahoo.com", "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 ??
Re: Whois script help
by DrHyde (Prior) on Jan 12, 2005 at 09:59 UTC
    Where exactly is that message coming from? If from whoisip_query then you have a bug to report to the author of Net::Whois::IP. The bug would be that the module does not cope correctly with the bad data you are supplying - www.yahoo.com is not an IP address.

    As for solving your problem ...

    for i in `cat list-of-domains`; do host -t NS $i; done

Re: Whois script help
by melora (Scribe) on Jan 12, 2005 at 14:34 UTC
    My suggestion would be that you consider temporarily not working on getting the script to run as a CGI. In my personal experience I find it easier to find a bug by running my script (even if it's CGI) at the command line, than as a CGI. "Internal server error" just does not normally give me enough information for my debug work.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://421334]
Approved by Limbic~Region
Front-paged by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-16 18:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found