I am totally out of my depth here. I've been asked to write a whois program that will allow us to take a user-supplied URL and do a whois lookup on it (actually, the program is supposed to do one heck of a lot more, but this is just to keep it simple).

I've never worked with this type of Perl before, so I'm scrambling around reading the Cookbook, RFCs, and manpages. The problem that I am having is that some valid domains are not resolving. Entering www.perlmonks.org works fine, but www.maserith.com (my previous employer) does not, yet maserith.com is a valid domain name. From what I can tell, this appears to be a limitation of the Net::Whois module, but I'm just not sure.

I've started working on another script which will keep following through and finding successive whois servers and grab the info, yet it seems like someone would have written something like this before. So far, it works okay, but I don't want to reinvent a wheel that I poorly understand. Below is the first script which does not resolve www.maserith.com (I've made it as small as possible while still having the 'feel' of what I'm trying to do).

use warnings; use strict; use Socket; use Net::Whois; use Carp; my ( $domain, $fqdn, $four_byte, $ip ); print "Gimme a domain name, cowboy: "; chomp ( $fqdn = lc <STDIN> ); # Extract domain from potentially sloppy input ( $domain ) = ( $fqdn =~ m!^(?:[^/]+/?/)?([^/]+)! ); # Get IP address $four_byte = inet_aton( $domain ); if ( $four_byte ) { $ip = inet_ntoa( inet_aton( $domain ) ); print "IP address is $ip\n"; whois ( get_domain( $domain ) ); } else { print "'$domain' does not resolve to an IP address.\n"; } sub whois { my $domain = shift; my $w = new Net::Whois::Domain $domain or die "Can't connect to Whois server\n"; unless ($w->ok) { croak "No match for $domain" }; print "Domain: ", $w->domain, "\n"; print "Name: ", $w->name, "\n"; print "Tag: ", $w->tag, "\n"; } sub get_domain { # Yeah, this is ugly and I don't like it. # I reverse the sections of the user-supplied domain name and then # use successive portions of it until I get a resolution my @segment = reverse split /\./, shift; my $domain; SEARCH_FOR_DOMAIN: { foreach ( @segment ) { ( $domain = $_, next ) if not $domain; $domain = $_ . ".$domain"; last SEARCH_FOR_DOMAIN if inet_aton( $domain ); } return 0; } return $domain; }
Can any monks give me pointers on which direction I should go? My other, hand-rolled, script successfully retrieves the info, but I am very unconfident in what I'm doing here. Is there something in the above script that I am just missing, or is Net::Whois no longer reliable?

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to Net::Whois troubles by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.