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 ); # 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; }