#!/usr/bin/perl -w use strict; use Net::Whois::Raw qw( $OMIT_MSG $CHECK_FAIL $CHECK_EXCEED $CACHE_DIR $CACHE_TIME $USE_CNAMES $TIMEOUT @SRC_IPS ); $OMIT_MSG = 2; # 0, 1, or 2: This will attempt to strip several known copyright messages and disclaimers sorted by servers $CHECK_FAIL = 1; # Does not work: $CACHE_DIR = "/tmp/whois_raw/"; my $DOMAIN = $ARGV[0] || 'infocopter.com'; &main(); sub main() { my $arrayref = Net::Whois::Raw::get_whois($DOMAIN, undef, 'QRY_ALL'); my %HASH = (); my $i = 0; foreach my $hash (@$arrayref) { foreach (keys %$hash) { $HASH{"$_\t$i"} = $hash->{$_}; } } #print "srv = \"", $HASH{"srv\t0"}, "\"\n"; my $text = ''; foreach (sort keys %HASH) { next unless /^text/; $text .= "$HASH{$_}\n"; } my $begin = 'Administrative'; $begin = '^Holder' if $DOMAIN =~ /\.ch$/i; my $last = '-------------------------X42----'; $last = 'Contractual Language:' if $DOMAIN =~ /\.ch$/i; my @whois_lines = split /\n/, $text; for ($i = 0; $i < $#whois_lines; $i++) { # print "== [$i] $whois_lines[$i]\n"; last if $whois_lines[$i] =~ /$begin.*\:/; } my @result = (); for ($i = $i + 1; $i < $#whois_lines; $i++) { chomp $whois_lines[$i]; last unless $whois_lines[$i]; $whois_lines[$i] = &trim($whois_lines[$i]); last if $whois_lines[$i] =~ /$last/; $whois_lines[$i] =~ s/,$//; if ($whois_lines[$i]) { push(@result, $whois_lines[$i]); # print "=========> \"$whois_lines[$i]\"\n"; } } my $holder_name = shift @result || ''; print "Name: $holder_name\n"; my $holder_address = (join ", ", @result) || ''; print "Address: $holder_address\n"; } sub trim ($) { join " ", grep { $_ } split / /, $_[0]; }