| 1 | package Net::ParseWhois::Domain; | ||||||||||||||||||
| 2 | 1 | require 5.004; | |||||||||||||||||
| 3 | |||||||||||||||||||
| 4 | 1 | $Net::ParseWhois::Domain::VERSION = 0.5; | |||||||||||||||||
| 5 | 1 | @Net::ParseWhois::Domain::ISA = qw(Net::ParseWhois); | |||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 1 | ▶ | use Net::ParseWhois::Domain::Registrar; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | #use strict; | ||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 1 | ▶ | BEGIN { | ||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.7
| |||||||||||||||||||
| 12 | 1 | ▶ | if (eval { require Locale::Country }) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 13 | 0 | Locale::Country->import(qw(code2country country2code)); | |||||||||||||||||
| 14 | } else { | ||||||||||||||||||
| 15 | 0 | ▶ | *code2country = sub { ($_[1] =~ /^[^\W\d_]{2}$/i) && $_[1] }; | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||
| 16 | 0 | ▶ | *country2code = sub { undef }; | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||
| 17 | } | ||||||||||||||||||
| 18 | } | ||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||
| 21 | # Initialization | ||||||||||||||||||
| 22 | 0 | my $obj = shift; | |||||||||||||||||
| 23 | 0 | ▶ | my $class = ref($obj) || 'Net::ParseWhois::Domain'; | ||||||||||||||||
|
Condition0%0/2
ref $obj || 'Net::ParseWhois::Domain'
MC/DC0%0/1
ref $obj || 'Net::ParseWhois::Domain'
ref $obj
Truth table0%0/2
A
A= ref $obj
| |||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 0 | ▶ | croak "usage: new \$class DOMAIN" if (!@_); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 | ▶ | if ($opt->{'debug'}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 | 0 | ▶ | sub chase_referral { | ||||||||||||||||
|
Subroutine
chase_referral: not called CC=24 SCAR=64.0
Pod
undocumented
| |||||||||||||||||||
| 45 | 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 | ▶ | warn "tld = $tld\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 54 | |||||||||||||||||||
| 55 | 0 | ▶ | $self->{'base_server_name'} = $self->TLDs->{$tld} if defined $self->TLDs->{$tld}; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | 0 | ▶ | warn "base_server_name = $self->{'base_server_name'}\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 58 | |||||||||||||||||||
| 59 | 0 | ▶ | if (!$self->{'base_server_name'}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 | ▶ | if ($self->TLDModel->{$tld} eq "thick") { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 | ▶ | if ($self->{'base_server_name'} eq "whois.publicinterestregistry.net") { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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} ) { | |||||||||||||||||
| 87 | 0 | ▶ | warn "whois line = $t ..\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | # Domain not found at this whois server | ||||||||||||||||||
| 90 | 0 | ▶ | if ($t =~ /^No match for \".*\"/i) { # Tightened pattern matching --jcm | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 91 | 0 | $self->{'MATCH'} = 0; | |||||||||||||||||
| 92 | 0 | ▶ | warn "Found 'No match for ' in results. MATCH = $self->{'MATCH'}\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 | ▶ | warn "whois_referral = $1\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 98 | 0 | ▶ | warn "MATCH = $self->{'MATCH'}\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 99 | # Registered nameserver for this domain (assumes match found) | ||||||||||||||||||
| 100 | } elsif ($t =~ /Name Server: (\S+)/) { | ||||||||||||||||||
| 101 | 0 | push(@{ $self->{'nameservers'} }, $1); | |||||||||||||||||
| 102 | 0 | ▶ | warn "nameserver: $1\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 103 | } | ||||||||||||||||||
| 104 | } | ||||||||||||||||||
| 105 | |||||||||||||||||||
| 106 | |||||||||||||||||||
| 107 | # If a referral was found... | ||||||||||||||||||
| 108 | 0 | ▶ | if ($self->{'whois_referral'}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 109 | 0 | ▶ | warn "Chasing referral to $self->{'whois_referral'}\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 110 | |||||||||||||||||||
| 111 | # Create referral handle based on whois server name given by | ||||||||||||||||||
| 112 | # previous query. | ||||||||||||||||||
| 113 | 0 | ▶ | $ref = Net::ParseWhois::Domain::Registrar::registrar_data()->{$self->{'whois_referral'}} || ""; | ||||||||||||||||
|
Condition0%0/2
Net::ParseWhois::Domain::Registrar::registrar_data()->{$self->{'whois_referral'}} || ''
MC/DC0%0/1
Net::ParseWhois::Domain::Registrar::registrar_data()->{$self->{'whois_referral'}} || ''
Net::ParseWhois::Domain::Registrar::registrar_data()->{$self->{'whois_referral'}}
Truth table0%0/2
A
A= Net::ParseWhois::Domain::Registrar::registrar_data()->{$self->{'whois_referral'}}
| |||||||||||||||||||
| 114 | |||||||||||||||||||
| 115 | # If the referred whois server isn't recoginized... | ||||||||||||||||||
| 116 | 0 | ▶ | unless ($ref) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 | ▶ | warn "Sorry, I don't know how to parse output from $self->{'whois_referral'}\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 | ▶ | warn "Loaded $class Registrar module\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 }, | |||||||||||||||||
| 135 | domain => $self->{'domain'}, | ||||||||||||||||||
| 136 | whois_referral => $self->{'whois_referral'}, | ||||||||||||||||||
| 137 | 0 | debug => $self->{'debug'} | |||||||||||||||||
| 138 | } ); | ||||||||||||||||||
| 139 | |||||||||||||||||||
| 140 | 0 | ▶ | warn "Created new $class object.\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 141 | 0 | ▶ | warn "$class->follow_referral = $rc->follow-referral\n" if $self->debug; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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 | 0 | ▶ | sub ok { | ||||||||||||||||
|
Subroutine
ok: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 154 | 0 | my $self = shift; | |||||||||||||||||
| 155 | 0 | $self->{MATCH}; | |||||||||||||||||
| 156 | } | ||||||||||||||||||
| 157 | |||||||||||||||||||
| 158 | 1 | 1; | |||||||||||||||||