line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::ParseWhois::Domain; |
2
|
|
|
|
|
|
|
require 5.004; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
$Net::ParseWhois::Domain::VERSION = 0.5; |
5
|
|
|
|
|
|
|
@Net::ParseWhois::Domain::ISA = qw(Net::ParseWhois); |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
523
|
use Net::ParseWhois::Domain::Registrar; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
8
|
|
|
|
|
|
|
#use strict; |
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1056
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
50
|
|
1
|
|
2
|
if (eval { require Locale::Country }) { |
|
1
|
|
|
|
|
822
|
|
13
|
1
|
|
|
|
|
33156
|
Locale::Country->import(qw(code2country country2code)); |
14
|
|
|
|
|
|
|
} else { |
15
|
0
|
0
|
|
|
|
|
*code2country = sub { ($_[1] =~ /^[^\W\d_]{2}$/i) && $_[1] }; |
|
0
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
*country2code = sub { undef }; |
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
|
|
|
|
|
|
# Initialization |
22
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
23
|
0
|
|
0
|
|
|
|
my $class = ref($obj) || 'Net::ParseWhois::Domain'; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
croak "usage: new \$class DOMAIN" if (!@_); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $self = { 'domain' => shift, |
28
|
|
|
|
|
|
|
'base_server_name' => 'whois.internic.net', |
29
|
|
|
|
|
|
|
'base_server_addr' => undef, |
30
|
|
|
|
|
|
|
'whois_referral' => undef, |
31
|
|
|
|
|
|
|
'nameservers' => undef |
32
|
|
|
|
|
|
|
}; |
33
|
0
|
|
|
|
|
|
bless($self, $class); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $opt = shift; |
36
|
0
|
0
|
|
|
|
|
if ($opt->{'debug'}) { |
37
|
0
|
|
|
|
|
|
$self->debug( $opt->{'debug'} ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $self->chase_referral; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# trys to chase_referral in specific registrar class or sets $self->ok = 0 |
44
|
|
|
|
|
|
|
sub chase_referral { |
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
0
|
|
|
|
|
|
my @zone_parts = split(/\./, $self->{'domain'}); |
47
|
0
|
|
|
|
|
|
my $tld = $zone_parts[$#zone_parts]; |
48
|
0
|
|
|
|
|
|
my ($text, $t, $ref, $class, $rc); |
49
|
0
|
|
|
|
|
|
$rc = 0; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#uppercase key |
52
|
0
|
|
|
|
|
|
$tld =~ tr /a-z/A-Z/; |
53
|
0
|
0
|
|
|
|
|
warn "tld = $tld\n" if $self->debug; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
$self->{'base_server_name'} = $self->TLDs->{$tld} if defined $self->TLDs->{$tld}; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
warn "base_server_name = $self->{'base_server_name'}\n" if $self->debug; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if (!$self->{'base_server_name'}) { |
60
|
0
|
|
|
|
|
|
die "unknown TLD - $tld\n"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# If this TLD uses a thick model, we don't need to chase referrals |
64
|
|
|
|
|
|
|
# for it, we have a single authoritative source to query. Sort of |
65
|
|
|
|
|
|
|
# a kludge to make sure correct Registrar module is called. |
66
|
|
|
|
|
|
|
# --jcm, 11/10/05 |
67
|
0
|
0
|
|
|
|
|
if ($self->TLDModel->{$tld} eq "thick") { |
68
|
0
|
|
|
|
|
|
$self->{'whois_referral'} = $self->{'base_server_name'}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# = make NSI Registry return only one result. enter just |
72
|
|
|
|
|
|
|
# register.com there without the equal to see what happens.. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Unfortunately, that WON'T work with the PIR whois server. Kludge |
75
|
|
|
|
|
|
|
# to get around it for now, will need to add search format data |
76
|
|
|
|
|
|
|
# to the class so this will be self-contained and not need any |
77
|
|
|
|
|
|
|
# special checks. --jcm, 11/10/05 |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if ($self->{'base_server_name'} eq "whois.publicinterestregistry.net") { |
80
|
0
|
|
|
|
|
|
$text = $self->_send_to_sock($self->_connect, "$self->{'domain'}\x0d\x0a"); |
81
|
|
|
|
|
|
|
} else { |
82
|
0
|
|
|
|
|
|
$text = $self->_send_to_sock($self->_connect, "=$self->{'domain'}\x0d\x0a"); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Read raw results of WHOIS query and do some initial parsing |
86
|
0
|
|
|
|
|
|
foreach $t (@{ $text} ) { |
|
0
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
warn "whois line = $t ..\n" if $self->debug; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Domain not found at this whois server |
90
|
0
|
0
|
|
|
|
|
if ($t =~ /^No match for \".*\"/i) { # Tightened pattern matching --jcm |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->{'MATCH'} = 0; |
92
|
0
|
0
|
|
|
|
|
warn "Found 'No match for ' in results. MATCH = $self->{'MATCH'}\n" if $self->debug; |
93
|
|
|
|
|
|
|
# Match found! But we need to follow a referral |
94
|
|
|
|
|
|
|
} elsif ($t =~ /Whois Server: (\S+)/) { |
95
|
0
|
|
|
|
|
|
$self->{'MATCH'} = 1; |
96
|
0
|
|
|
|
|
|
$self->{'whois_referral'} = $1; |
97
|
0
|
0
|
|
|
|
|
warn "whois_referral = $1\n" if $self->debug; |
98
|
0
|
0
|
|
|
|
|
warn "MATCH = $self->{'MATCH'}\n" if $self->debug; |
99
|
|
|
|
|
|
|
# Registered nameserver for this domain (assumes match found) |
100
|
|
|
|
|
|
|
} elsif ($t =~ /Name Server: (\S+)/) { |
101
|
0
|
|
|
|
|
|
push(@{ $self->{'nameservers'} }, $1); |
|
0
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
warn "nameserver: $1\n" if $self->debug; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# If a referral was found... |
108
|
0
|
0
|
|
|
|
|
if ($self->{'whois_referral'}) { |
109
|
0
|
0
|
|
|
|
|
warn "Chasing referral to $self->{'whois_referral'}\n" if $self->debug; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Create referral handle based on whois server name given by |
112
|
|
|
|
|
|
|
# previous query. |
113
|
0
|
|
0
|
|
|
|
$ref = Net::ParseWhois::Domain::Registrar::registrar_data()->{$self->{'whois_referral'}} || ""; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# If the referred whois server isn't recoginized... |
116
|
0
|
0
|
|
|
|
|
unless ($ref) { |
117
|
|
|
|
|
|
|
# This is an unknown registrar |
118
|
0
|
|
|
|
|
|
$ref = Net::ParseWhois::Domain::Registrar::registrar_data()->{'unknown_registrar'}; |
119
|
0
|
|
|
|
|
|
$ref->{'UNKNOWN_REGISTRAR'} = 1; |
120
|
0
|
|
|
|
|
|
$ref->{'error'} = "Sorry, I don't know how to parse output from $self->{'whois_referral'}"; |
121
|
0
|
0
|
|
|
|
|
warn "Sorry, I don't know how to parse output from $self->{'whois_referral'}\n" if $self->debug; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Get the class name for this registrar |
125
|
0
|
|
|
|
|
|
$class = 'Net::ParseWhois::Domain::Registrar::' . $ref->{'class'}; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Load that registrar's module |
128
|
0
|
|
|
|
|
|
$self->_load_module($class); |
129
|
0
|
0
|
|
|
|
|
warn "Loaded $class Registrar module\n" if $self->debug; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Now create a new instance of this particular registrar |
132
|
|
|
|
|
|
|
# module, using the referral data, domain name and of |
133
|
|
|
|
|
|
|
# course the whois server |
134
|
0
|
|
|
|
|
|
$rc = $class->new( { %{ $ref }, |
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
domain => $self->{'domain'}, |
136
|
|
|
|
|
|
|
whois_referral => $self->{'whois_referral'}, |
137
|
|
|
|
|
|
|
debug => $self->{'debug'} |
138
|
|
|
|
|
|
|
} ); |
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
warn "Created new $class object.\n" if $self->debug; |
141
|
0
|
0
|
|
|
|
|
warn "$class->follow_referral = $rc->follow-referral\n" if $self->debug; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return $rc->follow_referral; |
144
|
|
|
|
|
|
|
} else { |
145
|
|
|
|
|
|
|
# TODO catch if no whois_referral line .. set $self->{error}, something |
146
|
|
|
|
|
|
|
# Net::Whois behavior is to just return undef |
147
|
0
|
|
|
|
|
|
$self->{'error'} = "No WHOIS referral server found. Maybe I'm confused..."; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
return $self; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub ok { |
154
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
155
|
0
|
|
|
|
|
|
$self->{MATCH}; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |