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

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.

Replies are listed 'Best First'.
Re: Net::Whois troubles
by btrott (Parson) on Nov 30, 2000 at 06:06 UTC
    Looking at the innards of Net::Whois when it makes a request for maserith.com, the results from the whois server are coming back in a form that Net::Whois doesn't understand. Which is bad news, because even though it's a valid return, Net::Whois can't understand it.

    Which leaves you in the position of patching Net::Whois, perhaps. :)

    On the question of whether it's (un)reliable: you might take a look at this message from the modules@perl.org list. I'm not in a position to say one way or the other who's in the right :), but it certainly does seem that Net::Whois needs some changes/fixes.

    And with that in mind, you might take a look at the module mentioned in that message, Net::ParseWhois. I just tried it myself, and it works for maserith.com. The interface seems to be identical to that of Net::Whois; just change instances of Net::Whois to Net::ParseWhois and you're done:

    use Net::ParseWhois; my $w = new Net::ParseWhois::Domain "maserith.com"; ....
      btrott, that is exactly what I was looking for. It seems to work perfectly and when I dumped it into a much larger and more substantial script, everything came out exactly the way I wanted it. After reading about the dispute that's keeping this module from CPAN, all I can think is that everyone needs to put their frickin' egos aside and let people use this.

      Personally, I'm going to send an e-mail to the author thanking him for creating this and perhaps urge him to upload it anyway (I'll have to reread the correspondence, but we really could use this module). I wonder how many other people were beating their heads over this situation and were being forced to do it by hand?

      A thousand thanks!!!

      Cheers,
      Ovid

      Update: I read the correspondense too quickly. I'll definitely thank the author, but I think I was premature in thinking I would urge him to upload regardles of the dispute. I have to confess that I sympathize with Abraham's feeling's about Net::Whois's source code (well, he hinted at them, he didn't explicitly state them). It looks pretty ugly.

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

        see my code at Whois+DNS for a cool application of Net::ParseWhois.
Re: Net::Whois troubles
by marius (Hermit) on Nov 30, 2000 at 10:55 UTC
    Anothing thing you may want to try search for is Net::XWhois. Works like a champ for non-US TLD's as well with a bit of work.

    -marius
    A reply falls below the community's threshold of quality. You may see it by logging in.