Ovid has asked for the wisdom of the Perl Monks concerning the following question:
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).
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?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; }
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 | |
by Ovid (Cardinal) on Nov 30, 2000 at 06:25 UTC | |
by mdillon (Priest) on Nov 30, 2000 at 09:10 UTC | |
|
Re: Net::Whois troubles
by marius (Hermit) on Nov 30, 2000 at 10:55 UTC | |
|