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