blob: 56d9a7e8d0504bf0b34c6dff12f92cc59e1b6aec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#!/usr/bin/perl -w
use Net::Whois::Raw qw( whois $OMIT_MSG $CHECK_FAIL $TIMEOUT $CACHE_DIR );
use Getopt::Std;
use strict;
use vars qw($opt_s $opt_c $opt_S $opt_C $opt_t $opt_T $opt_h);
getopts("scSCtT:h");
if ($opt_h) {
print <<EOM;
$0 [ -s | -S ] [ -c | -C ] [ -t <timeout> ] [ -T] <domain> [ <server> ]
The -s switch attempts to strip the copyright message or disclaimer.
The -S switch will attempt some exra rules for it.
The -c switch attempts to return an empty answer for failed searches.
The -C switch will attempt some exra rules for it.
The -T switch takes a parameter that is used for the timeout for
connection attempts.
The -t switch enables caching.
EOM
exit;
}
$OMIT_MSG = $CHECK_FAIL = 0;
$OMIT_MSG = 1 if $opt_s;
$OMIT_MSG = 2 if $opt_S;
$CHECK_FAIL = 1 if $opt_c;
$CHECK_FAIL = 2 if $opt_C;
$TIMEOUT = $opt_T;
$CACHE_DIR = undef;
if ($opt_t) {
if ($^O =~ /Win/) {
$CACHE_DIR = $ENV{'TEMP'} || "C:\\temp";
} else {
$CACHE_DIR = $ENV{'TEMP'} || "/tmp";
my @ent = getpwuid($>);
if (@ent) {
foreach ("/tmp/$ent[0]", "$ent[7]/.pwhois") {
mkdir $_, 0644;
if (open(O, ">$_/__$$-$$.tmp")) {
close(O);
unlink "$_/__$$-$$.tmp";
$CACHE_DIR = $_;
last;
}
}
}
}
}
my $dom = $ARGV[0] || die "Usage: $0 domain";
my $server = $ARGV[1];
eval {
my $result = whois($dom, $server);
if ($result) {
print $result;
} else {
print STDERR "Failed.\n";
}
};
if ($@) {
my $err = $@;
$err =~ s/\s+at \S+ line \d+\.$//;
print "\nWhois information could not be fetched:\n$err\n";
exit -1;
}
__END__
=head1 NAME
pwhois - Perl written whois client
=head1 SYNOPSIS
pwhois perl.com
pwhois gnu.org
pwhois -s police.co.il
pwhois -c there.is.no.tld.called.foobar
pwhois yahoo.com whois.networksolutions.com
pwhois -T 10 funet.fi
etc etc.....
=head1 DESCRIPTION
Just invoke with a domain name, optionally with a whois server name.
The B<-s> switch attempts to strip the copyright message or disclaimer.
The B<-c> switch attempts to return an empty answer for failed searches.
The B<-T> switch takes a parameter that is used for the timeout for
connection attempts.
=head1 AUTHOR
Ariel Brosh, B<schop@cpan.org>
=head1 SEE ALSO
L<Net::Whois::Raw>.
|