Example
#!/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 = '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";
foreach (sort keys %HASH) {
next unless /^text/;
print "$_ = ", $HASH{$_}, "\n";
}
}
Variables
$CACHE_DIR = "/var/spool/pwhois/"; # Whois information will be
cached in this directory. Default is no cache.
$CACHE_TIME = 24; # Cache files will be cleared after not accessed
for a specific number of hours. Documents will not be
cleared if they keep get requested for, independent
of disk space. Default is not to clear the cache.
$TIMEOUT = 10; # Cancel the request if connection is not made within
a specific number of seconds.
Another Example
#!/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]; }
See also:
/usr/lib/perl5/site_perl/5.8.6/Net/Whois/Raw/Data.pm
search.cpan.org/~despair/Net-Whois-Raw/lib/Net/Whois/Raw.pm↑