script/no_whois.pl untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod n/a totaltotal 0.0% 0 / 102 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5 use NOLookup::Whois::WhoisLookup;
6 use Encode;
7 use vars qw($opt_q $opt_v $opt_h $opt_s $opt_p);
8 use Getopt::Std;
9 use Pod::Usage;
10  
11 use Data::Dumper;
12 $Data::Dumper::Indent=1;
13  
14 &getopts('hvq:s:p:'); # q:query, v=verbose dump, s:whois server, p:whois port
15  
16 if ($opt_h) {
17 pod2usage();
18 }
19  
20 unless ($opt_q) {
21 pod2usage("A query must be specified!\n");
22 }
23  
24 my $q = decode('UTF-8', $opt_q);
25  
26 my $SERVER = $opt_s || 'whois.norid.no';
27 my $PORT = $opt_p || 43;
28  
29 my ($wh, $do, $ho) = NOLookup::Whois::WhoisLookup->new($q, $SERVER, $PORT);
30  
31 if ($wh->errno) {
32 print STDERR "Whois error: ", $wh->errno, "\n";
33 if ($wh->raw_text) {
34 print STDERR "Raw text : ", $wh->raw_text, "\n";
35 }
36 exit;
37 }
38  
39 #print STDERR "wh: ", Dumper $wh;
40  
41 if ($do) {
42 # Present if a domain name or handle is queried,
43 # and a match was found
44 my $hret = "object is";
45  
46 print "Domain name : ", encode('UTF-8', $do->domain_name), "\n";
47 print "Registrar handle : ", $do->registrar_handle, "\n";
48 print "Tech-c handle : ", $do->tech_c_handle, "\n";
49 foreach my $nh (sort(split("\n", $do->name_server_handle))) {
50 print "Nameserver handle: $nh\n";
51 }
52  
53 print "DNSSEC signed : ";
54 if ($do->dnssec) {
55 print "yes\n";
56 } else {
57 print "no\n";
58 }
59
60 if ($ho) {
61 print "Holder name : ", encode('UTF-8', $ho->name), "\n";
62 print "Holder address : ", encode('UTF-8', $ho->post_address), "\n";
63 print "Holder email : ", encode('UTF-8', $ho->email_address), "\n";
64 print "Id type : ", encode('UTF-8', $ho->id_type), "\n";
65 print "Id number : ", encode('UTF-8', $ho->id_number), "\n";
66 if ($ho->organization_type) {
67 print "Organization type: ", encode('UTF-8', $ho->organization_type), "\n";
68 }
69 $hret = "and holder objects are";
70  
71 }
72 if ($opt_v) {
73 print "Domain object raw text: ", Dumper($do->raw_text);
74 print "Host object raw text : ", Dumper($ho->raw_text) if ($ho);
75 } else {
76 print "Domain $hret returned, use -v to see the details\n";
77 }
78  
79 } else {
80 # $wh contains the result of all other queries
81  
82 if ($opt_v) {
83 print "Whois raw data: ", Dumper($wh->raw_text);
84 } else {
85 print "A whois object is returned, use -v to see the details\n";
86
87 }
88 }
89  
90 =pod
91  
92 =head1 NAME
93  
94 no_whois.pl
95  
96 =head1 DESCRIPTION
97  
98 Uses NOLookup::Whois::WhoisLookup to perform lookup on some query
99 from the Norid whois service.
100  
101 =head1 USAGE
102  
103 no_whois.pl [hvq:] <querystring>
104  
105 Arguments:
106  
107 -q: query
108 -v: verbose dump of the returned raw whois response
109 -h: this help
110  
111 Examples:
112  
113 Query on a domain name:
114 perl no_whois.pl -q norid.no
115  
116 Query on a organization number:
117 perl no_whois.pl -q 985821585
118  
119 Query on a domain name, verbose dump to see raw response:
120 perl no_whois.pl -q norid.no -v
121  
122 Query on a contact handle, verbose dump to see raw response:
123 perl no_whois.pl -q UNA165O-NORID -v
124  
125 =cut
126  
127 1;
128  
129