blib/lib/Net/Whois/IANA.pm

filter: Statementstmt 85.3% 268 / 314 Branchbran 65.0% 108 / 166 Conditioncond 40.6% 85 / 209 MC/DCmcdc 16.8% 18 / 107 Subroutinesub 94.4% 34 / 36 Podpod 7.6% 2 / 26 totaltotal 60.0% 515 / 858 CC 159 SCAR 36.6
CC
159
Cov
67%
is_valid_ipv6
272.0
set_source
68.6
ripe_process_query
39.9
CRAP 38.9
↑ Summary
1 package Net::Whois::IANA;
2 10 $Net::Whois::IANA::VERSION = '0.50';
3 10 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use IO::Socket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Net::CIDR ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # ABSTRACT: Net::Whois::IANA - A universal WHOIS data extractor.
15  
16 10 our $WHOIS_PORT = 43;
17 10 our $WHOIS_TIMEOUT = 30;
18 10 our @DEFAULT_SOURCE_ORDER = qw(arin ripe apnic lacnic afrinic);
19  
20 10 our %IANA;
21 10 our @IANA;
22  
23 10 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
24 # populate the hash at compile time
25  
26 10 %IANA = (
27 apnic => [ [ 'whois.apnic.net', $WHOIS_PORT, $WHOIS_TIMEOUT, \&apnic_query ], ],
28 ripe => [ [ 'whois.ripe.net', $WHOIS_PORT, $WHOIS_TIMEOUT, \&ripe_query ], ],
29 arin => [ [ 'whois.arin.net', $WHOIS_PORT, $WHOIS_TIMEOUT, \&arin_query ], ],
30 lacnic => [ [ 'whois.lacnic.net', $WHOIS_PORT, $WHOIS_TIMEOUT, \&lacnic_query ], ],
31 afrinic => [ [ 'whois.afrinic.net', $WHOIS_PORT, $WHOIS_TIMEOUT, \&afrinic_query ],
32 ],
33 );
34  
35 10 @IANA = sort keys %IANA;
36  
37 # accessors
38 # do not use AUTOLOAD - only accept lowercase function name
39 # define accessors at compile time
40 10 my @accessors = qw{country netname descr status source server inetnum inet6num cidr abuse fullinfo};
41  
42 10 foreach my $accessor (@accessors) {
43 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
44 26 ▶ *$accessor = sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
45 26 my ($self) = @_;
46 26 ▶ die qq[$accessor is a method call] unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 26 26
47 26 ▶ return unless $self->{QUERY};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"QUERY"} 0 26 26
48 26 return $self->{QUERY}->{$accessor};
49 110 };
50 }
51  
52 10 *desc = \&descr; # backward compatibility
53 }
54  
55 10 our @EXPORT = qw( @IANA %IANA );
56  
57 9 ▶sub new ($) {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
58  
59 9 my $proto = shift;
60 9 ▶ my $class = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
090
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
61 9 my $self = {};
62  
63 9 bless $self, $class;
64  
65 9 return $self;
66 }
67  
68 19 ▶sub whois_connect ($;$$) {
Subroutine whois_connect: called CC=7 SCAR=21.5
Pod undocumented
69 19 my ( $host, $port, $timeout ) = @_;
70  
71 19 ▶ ( $host, $port, $timeout ) = @$host if ref $host;
Branch: 1 branch
BranchTrueFalseTotal
if ref $host 17 2 19
72  
73 19 ▶ $port ||= $WHOIS_PORT;
Condition66%2/3
$port ||= $Net::Whois::IANA::WHOIS_PORT
l!l&&r!l&&!r
2170
MC/DC0%0/2
$port ||= $Net::Whois::IANA::WHOIS_PORT
$port $Net::Whois::IANA::WHOIS_PORT
Truth table66%2/3
A ||= B
A= $portB= $Net::Whois::IANA::WHOIS_PORT
ABresult
1X1
011
000
74 19 ▶ $timeout ||= $WHOIS_TIMEOUT;
Condition66%2/3
$timeout ||= $Net::Whois::IANA::WHOIS_TIMEOUT
l!l&&r!l&&!r
2170
MC/DC0%0/2
$timeout ||= $Net::Whois::IANA::WHOIS_TIMEOUT
$timeout $Net::Whois::IANA::WHOIS_TIMEOUT
Truth table66%2/3
A ||= B
A= $timeoutB= $Net::Whois::IANA::WHOIS_TIMEOUT
ABresult
1X1
011
000
75  
76 #my $port = $host_ref->[1] || $WHOIS_PORT;
77 #my $timeout = $host_ref->[2] || $WHOIS_TIMEOUT;
78 #my $host = $host_ref->[0];
79 19 my $retries = 2;
80 19 my $sleep = 2;
81  
82 19 my $sock;
83  
84 19 foreach my $iter ( 0 .. $retries ) {
85 19 local $@;
86  
87 # catch errors
88 19 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $sock = "IO::Socket::INET"->new("PeerAddr", $host, "PeerPort", $port, "Timeout", $timeout); 1 } } and return $sock 19 0 19
89 19 $sock = IO::Socket::INET->new(
90 PeerAddr => $host,
91 PeerPort => $port,
92 Timeout => $timeout,
93 );
94 19 1;
95 } and return $sock;
96  
97 0 Carp::carp "Cannot connect to $host at port $port";
98 0 Carp::carp $@;
99 0 ▶ sleep $sleep unless $iter == $retries; # avoid the last sleep
Branch: 1 branch
BranchTrueFalseTotal
unless $iter == $retries 0 0 0
100 }
101 0 return 0;
102 }
103  
104 22 ▶sub is_valid_ipv4 ($) {
Subroutine is_valid_ipv4: called CC=3 SCAR=11.0
Pod undocumented
105  
106 22 my $ip = shift;
107  
108 22 ▶ return $ip
Condition83%5/6
$ip && $ip =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ && ($1 + 0 | $2 + 0 | $3 + 0 | $4 + 0) < 256
!ll&&!rl&&r
1120
$ip and $ip =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/
!ll&&!rl&&r
0121
MC/DC66%2/3
$ip && $ip =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ && ($1 + 0 | $2 + 0 | $3 + 0 | $4 + 0) < 256
$ip $ip =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ($1 + 0 | $2 + 0 | $3 + 0 | $4 + 0) < 256
Truth table75%3/4
A and B && C
A= $ipB= $ip =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/C= ($1 + 0 | $2 + 0 | $3 + 0 | $4 + 0) < 256
ABCresult
0XX0
10X0
1100
1111
109 && $ip =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/
110  
111 # not absolutely correct
112 && ( ( $1 + 0 ) | ( $2 + 0 ) | ( $3 + 0 ) | ( $4 + 0 ) ) < 0x100;
113 }
114  
115 0 ▶sub is_valid_ipv6 {
Subroutine is_valid_ipv6: not called CC=16 SCAR=56.1
Pod undocumented
116 0 my ($ip) = @_;
117  
118 return
119 0 ▶ if $ip =~ /^:[^:]/
Branch: 1 branch
BranchTrueFalseTotal
if $ip =~ /^:[^:]/ or $ip =~ /[^:]:$/ 0 0 0
Condition0%0/3
$ip =~ /^:[^:]/ or $ip =~ /[^:]:$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$ip =~ /^:[^:]/ or $ip =~ /[^:]:$/
$ip =~ /^:[^:]/ $ip =~ /[^:]:$/
Truth table0%0/3
A or B
A= $ip =~ /^:[^:]/B= $ip =~ /[^:]:$/
ABresult
1X1
011
000
120 || $ip =~ /[^:]:$/; # Can't have single : on front or back
121  
122 0 my @seg = split /:/, $ip, -1; # -1 to keep trailing empty fields
123 # Clean up leading/trailing double colon effects.
124 0 ▶ shift @seg if $seg[0] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $seg[0] eq "" 0 0 0
125 0 ▶ pop @seg if $seg[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $seg[-1] eq "" 0 0 0
126  
127 0 my $max = 8;
128 0 ▶ if ( $seg[-1] =~ tr/.// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seg[-1] =~ tr/.//) 0 0 0
129 0 ▶ return unless is_valid_ipv4( pop @seg );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_valid_ipv4(pop @seg) 0 0 0
130 0 $max -= 2;
131 }
132  
133 0 my $cmp;
134 0 for my $seg (@seg) {
135 0 ▶ if ( $seg eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seg eq "") 0 0 0
136  
137 # Only one compression segment allowed.
138 0 ▶ return if $cmp;
Branch: 1 branch
BranchTrueFalseTotal
if $cmp 0 0 0
139 0 ++$cmp;
140 0 next;
141 }
142 0 ▶ return if $seg =~ /[^0-9a-fA-F]/;
Branch: 1 branch
BranchTrueFalseTotal
if $seg =~ /[^0-9a-fA-F]/ 0 0 0
143 0 ▶ return if length $seg == 0 || length $seg > 4;
Branch: 1 branch
BranchTrueFalseTotal
if length $seg == 0 or length $seg > 4 0 0 0
Condition0%0/3
length $seg == 0 or length $seg > 4
l!l&&r!l&&!r
000
MC/DC0%0/2
length $seg == 0 or length $seg > 4
length $seg == 0 length $seg > 4
Truth table0%0/3
A or B
A= length $seg == 0B= length $seg > 4
ABresult
1X1
011
000
144 }
145 0 ▶ if ($cmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp) 0 0 0
146  
147 # If compressed, we need fewer than $max segments, but at least 1
148 0 ▶ return ( @seg && @seg < $max ) && 1; # true returned as 1
Condition0%0/5
@seg && @seg < $max && 1
!ll
00
@seg and @seg < $max
!ll&&!rl&&r
000
MC/DC0%0/2
@seg && @seg < $max && 1
@seg @seg < $max
Truth table0%0/3
A and B
A= @segB= @seg < $max
ABresult
0X0
100
111
149 }
150  
151 # Not compressed, all segments need to be there.
152 0 return $max == @seg;
153 }
154  
155 # Is valid IP v4 or IP v6 address.
156 23 ▶sub is_valid_ip ($) {
Subroutine is_valid_ip: called CC=3 SCAR=11.1
Pod undocumented
157 23 my ($ip) = @_;
158  
159 23 ▶ return unless defined $ip; # shortcut earlier
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 1 22 23
160 22 ▶ return index( $ip, ':' ) >= 0 ? is_valid_ipv6($ip) : is_valid_ipv4($ip);
Branch: 1 branch
BranchTrueFalseTotal
index($ip, ':') != -1 ? : 0 22 22
161 }
162  
163 16 ▶sub set_source ($$) {
Subroutine set_source: called CC=14 SCAR=42.3
Pod undocumented
164  
165 16 my $self = shift;
166 16 my $source = shift;
167  
168 16 ▶ $self->{source} = {%IANA} || return 0 unless $source;
Branch: 1 branch
BranchTrueFalseTotal
unless $source 2 14 16
Condition50%1/2
{%Net::Whois::IANA::IANA} || (return 0)
l!l
20
MC/DC0%0/1
{%Net::Whois::IANA::IANA} || (return 0)
{%Net::Whois::IANA::IANA}
Truth table50%1/2
A
A= {%Net::Whois::IANA::IANA}
Aresult
11
00
169 16 ▶ return 0 unless $source;
Branch: 1 branch
BranchTrueFalseTotal
unless $source 2 14 16
170 14 ▶ unless ( ref $source ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $source) 14 0 14
171 14 ▶ if ( $IANA{$source} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Whois::IANA::IANA{$source}) 13 1 14
172 13 $self->{source} = { $source => $IANA{$source} };
173 13 return 0;
174 }
175 1 return 1;
176 }
177 return 2
178 unless ref $source eq 'HASH'
179 0 ▶ && scalar grep { ref $_ && ref $_ eq 'ARRAY' && @{$_} && ref $_->[0] && ref $_->[0] eq 'ARRAY' && @{ $_->[0] } && $_->[0][0] } values %{$source} == scalar keys %{$source};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source eq "HASH" and scalar grep({ref $_ and ref $_ eq "ARRAY" and @{$_;} and ref $_->[0] and ref $_->[0] eq "ARRAY" and @{$_->[0];} and $_->[0][0];} values %{$source;} == scalar keys %{$source;}) 0 0 0
Condition0%0/20
ref $source eq "HASH" and scalar grep({ref $_ and ref $_ eq "ARRAY" and @{$_;} and ref $_->[0] and ref $_->[0] eq "ARRAY" and @{$_->[0];} and $_->[0][0];} values %{$source;} == scalar keys %{$source;})
!ll
00
ref $_ && ref $_ eq 'ARRAY' && @{$_;} && ref $_->[0] && ref $_->[0] eq 'ARRAY' && @{$_->[0];} && $_->[0][0]
!ll&&!rl&&r
000
ref $_ and ref $_ eq "ARRAY" and @{$_;} and ref $_->[0] and ref $_->[0] eq "ARRAY" and @{$_->[0];}
!ll&&!rl&&r
000
ref $_ and ref $_ eq "ARRAY" and @{$_;} and ref $_->[0] and ref $_->[0] eq "ARRAY"
!ll&&!rl&&r
000
ref $_ and ref $_ eq "ARRAY" and @{$_;} and ref $_->[0]
!ll&&!rl&&r
000
ref $_ and ref $_ eq "ARRAY" and @{$_;}
!ll&&!rl&&r
000
ref $_ and ref $_ eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/1
ref $source eq "HASH" and scalar grep({ref $_ and ref $_ eq "ARRAY" and @{$_;} and ref $_->[0] and ref $_->[0] eq "ARRAY" and @{$_->[0];} and $_->[0][0];} values %{$source;} == scalar keys %{$source;})
ref $source eq "HASH"
MC/DC0%0/7
ref $_ && ref $_ eq 'ARRAY' && @{$_;} && ref $_->[0] && ref $_->[0] eq 'ARRAY' && @{$_->[0];} && $_->[0][0]
ref $_ ref $_ eq "ARRAY" @{$_;} ref $_->[0] ref $_->[0] eq "ARRAY" @{$_->[0];} $_->[0][0]
Truth table0%0/2
A
A= ref $source eq "HASH"
Aresult
00
11
Truth table0%0/8
A and B and C and D and E and F && G
A= ref $_B= ref $_ eq "ARRAY"C= @{$_;}D= ref $_->[0]E= ref $_->[0] eq "ARRAY"F= @{$_->[0];}G= $_->[0][0]
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
180 0 $self->{source} = $source;
181 0 return 0;
182 }
183  
184 19 ▶sub init_query ($%) {
Subroutine init_query: called CC=5 SCAR=16.3
Pod undocumented
185  
186 19 my $self = shift;
187 19 my %param = @_;
188  
189 19 ▶ if ( !is_valid_ip( $param{-ip} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&is_valid_ip($param{"-ip"})) 3 16 19
190 3 warn q{
191 Method usage:
192 $iana->whois_query(
193 -ip=>$ip,
194 -debug=>$debug, # optional
195 -whois=>$whois | -mywhois=>\%mywhois, # optional
196 };
197 3 return {};
198 }
199  
200 16 ▶ my $set_source = $self->set_source( $param{-whois} || $param{-mywhois} );
Condition66%2/3
$param{'-whois'} || $param{'-mywhois'}
l!l&&r!l&&!r
1402
MC/DC50%1/2
$param{'-whois'} || $param{'-mywhois'}
$param{'-whois'} $param{'-mywhois'}
Truth table66%2/3
A || B
A= $param{'-whois'}B= $param{'-mywhois'}
ABresult
1X1
011
000
201 16 ▶ if ( $set_source == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($set_source == 1) { } 1 15 16
elsif ($set_source == 2) { } 0 15 15
202 1 warn "Unknown whois server requested. Known servers are:\n";
203 1 warn join( ", ", @IANA ) . "\n";
204 1 return {};
205 }
206 elsif ( $set_source == 2 ) {
207 0 warn q{
208 Custom sources must be of form:
209 %source = (
210 source_name1 => [
211 [ source_host, source_port || undef, source_timeout || undef, \&source_query || undef ],
212 ],
213 source_name1 => [
214 [ source_host, source_port || undef, source_timeout || undef, \&source_query || undef ],
215 ],
216 ...,
217 );
218 };
219 }
220 }
221  
222 64 ▶sub source_connect ($$) {
Subroutine source_connect: called CC=5 SCAR=16.7
Pod undocumented
223 64 my ( $self, $source_name ) = @_;
224  
225 64 foreach my $server_ref ( @{ $self->{source}{$source_name} } ) {
226 17 ▶ if ( my $sock = whois_connect($server_ref) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sock = &whois_connect($server_ref)) 17 0 17
227 17 my ( $whois_host, $whois_port, $whois_timeout, $query_code ) = @{$server_ref};
228 17 ▶ $self->{query_sub} = $query_code
Branch: 1 branch
BranchTrueFalseTotal
$query_code && ref $query_code eq 'CODE' ? : 17 0 17
Condition33%1/3
$query_code and ref $query_code eq "CODE"
!ll&&!rl&&r
0017
MC/DC0%0/2
$query_code and ref $query_code eq "CODE"
$query_code ref $query_code eq "CODE"
Truth table33%1/3
A and B
A= $query_codeB= ref $query_code eq "CODE"
ABresult
0X0
100
111
229 && ref $query_code eq 'CODE' ? $query_code : \&default_query;
230 17 $self->{whois_host} = $whois_host;
231 17 return $sock;
232 }
233 }
234 47 return undef;
235 }
236  
237 14 ▶sub post_process_query (%) {
Subroutine post_process_query: called CC=17 SCAR=31.1
Pod undocumented
238  
239 14 my %query = @_;
240 14 for my $qkey ( keys %query ) {
241 275 ▶ chomp $query{$qkey} if defined $query{$qkey};
Branch: 1 branch
BranchTrueFalseTotal
if defined $query{$qkey} 275 0 275
242 $query{abuse} = $query{$qkey} and last
243 275 ▶ if $qkey =~ /abuse/i && $query{$qkey} =~ /\@/;
Branch: 1 branch
BranchTrueFalseTotal
if $qkey =~ /abuse/i and $query{$qkey} =~ /\@/ 2 273 275
Condition75%6/8
$qkey =~ /abuse/i && $query{$qkey} =~ /\@/ && (($query{'abuse'} = $query{$qkey}) && (last))
!ll&&!rl&&r
27320
$qkey =~ /abuse/i and $query{$qkey} =~ /\@/
!ll&&!rl&&r
26672
$query{"abuse"} = $query{$qkey} and last
!ll
02
MC/DC0%0/3
$qkey =~ /abuse/i && $query{$qkey} =~ /\@/ && (($query{'abuse'} = $query{$qkey}) && (last))
$qkey =~ /abuse/i $query{$qkey} =~ /\@/ $query{"abuse"} = $query{$qkey}
Truth table50%2/4
A and B && C
A= $qkey =~ /abuse/iB= $query{$qkey} =~ /\@/C= $query{"abuse"} = $query{$qkey}
ABCresult
0XX0
10X0
1100
1111
244 }
245 14 ▶ unless ( $query{abuse} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query{"abuse"}) 12 2 14
246 12 ▶ if ( $query{fullinfo} && $query{fullinfo} =~ /(\S*abuse\S*\@\S+)/m ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($query{'fullinfo'} and $query{'fullinfo'} =~ /(\S*abuse\S*\@\S+)/m) { } 10 2 12
elsif ($query{'email'} or $query{'e-mail'} or $query{'orgtechemail'}) { } 1 1 2
Condition66%2/3
$query{"fullinfo"} and $query{"fullinfo"} =~ /(\S*abuse\S*\@\S+)/m
!ll&&!rl&&r
0210
MC/DC50%1/2
$query{"fullinfo"} and $query{"fullinfo"} =~ /(\S*abuse\S*\@\S+)/m
$query{"fullinfo"} $query{"fullinfo"} =~ /(\S*abuse\S*\@\S+)/m
Truth table66%2/3
A and B
A= $query{"fullinfo"}B= $query{"fullinfo"} =~ /(\S*abuse\S*\@\S+)/m
ABresult
0X0
100
111
247 10 $query{abuse} = $1;
248 }
249 ▶ elsif ( $query{email} || $query{'e-mail'} || $query{orgtechemail} ) {
Condition66%4/6
$query{"email"} or $query{"e-mail"} or $query{"orgtechemail"}
l!l&&r!l&&!r
101
$query{"email"} or $query{"e-mail"}
l!l&&r!l&&!r
011
MC/DC33%1/3
$query{"email"} or $query{"e-mail"} or $query{"orgtechemail"}
$query{"email"} $query{"e-mail"} $query{"orgtechemail"}
Truth table50%2/4
A or B or C
A= $query{"email"}B= $query{"e-mail"}C= $query{"orgtechemail"}
ABCresult
1XX1
01X1
0011
0000
250 $query{abuse} =
251 1 ▶ $query{email} || $query{'e-mail'} || $query{orgtechemail};
Condition33%2/6
$query{'email'} || $query{'e-mail'} || $query{'orgtechemail'}
l!l&&r!l&&!r
100
$query{"email"} or $query{"e-mail"}
l!l&&r!l&&!r
010
MC/DC0%0/3
$query{'email'} || $query{'e-mail'} || $query{'orgtechemail'}
$query{"email"} $query{"e-mail"} $query{'orgtechemail'}
Truth table25%1/4
A or B || C
A= $query{"email"}B= $query{"e-mail"}C= $query{'orgtechemail'}
ABCresult
1XX1
01X1
0011
0000
252 }
253 }
254 14 ▶ if ( !ref $query{cidr} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $query{"cidr"}) 2 12 14
255 2 ▶ if ( defined $query{cidr} && $query{cidr} =~ /\,/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $query{'cidr'} and $query{'cidr'} =~ /\,/) { } 0 2 2
Condition33%1/3
defined $query{"cidr"} and $query{"cidr"} =~ /\,/
!ll&&!rl&&r
020
MC/DC0%0/2
defined $query{"cidr"} and $query{"cidr"} =~ /\,/
defined $query{"cidr"} $query{"cidr"} =~ /\,/
Truth table33%1/3
A and B
A= defined $query{"cidr"}B= $query{"cidr"} =~ /\,/
ABresult
0X0
100
111
256 0 $query{cidr} = [ split( /\s*\,\s*/, $query{cidr} ) ];
257 }
258 else {
259 2 $query{cidr} = [ $query{cidr} ];
260 }
261 }
262  
263 14 return %query;
264 }
265  
266 19 ▶sub whois_query ($%) {
Subroutine whois_query: called CC=8 SCAR=21.9
Pod documented
267 19 my ( $self, %params ) = @_;
268  
269 19 $self->init_query(%params);
270 19 $self->{QUERY} = {};
271  
272 19 for my $source_name (@DEFAULT_SOURCE_ORDER) {
273 64 ▶ print STDERR "Querying $source_name ...\n" if $params{-debug};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"-debug"} 0 64 64
274 64 ▶ my $sock = $self->source_connect($source_name)
Condition80%4/5
$self->source_connect($source_name) || Carp::carp("Connection failed to $source_name." && (next))
l!l&&r!l&&!r
172720
"Connection failed to $source_name." && (next)
!ll
047
MC/DC0%0/2
$self->source_connect($source_name) || Carp::carp("Connection failed to $source_name." && (next))
$self->source_connect($source_name) Carp::carp("Connection failed to $source_name." && (next))
MC/DC0%0/1
"Connection failed to $source_name." && (next)
"Connection failed to $source_name."
Truth table33%1/3
A || B
A= $self->source_connect($source_name)B= Carp::carp("Connection failed to $source_name." && (next))
ABresult
1X1
011
000
Truth table50%1/2
A
A= "Connection failed to $source_name."
Aresult
00
11
275 || Carp::carp "Connection failed to $source_name." && next;
276 17 my %query = $self->{query_sub}( $sock, $params{-ip} );
277  
278 17 ▶ next unless keys %query;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %query 3 14 17
279 0 do { Carp::carp "Warning: permission denied at $source_name server $self->{whois_host}\n"; next }
280 14 ▶ if $query{permission} && $query{permission} eq 'denied';
Branch: 1 branch
BranchTrueFalseTotal
if ($query{"permission"} and $query{"permission"} eq "denied") 0 14 14
Condition33%1/3
$query{"permission"} and $query{"permission"} eq "denied"
!ll&&!rl&&r
0140
MC/DC0%0/2
$query{"permission"} and $query{"permission"} eq "denied"
$query{"permission"} $query{"permission"} eq "denied"
Truth table33%1/3
A and B
A= $query{"permission"}B= $query{"permission"} eq "denied"
ABresult
0X0
100
111
281 14 $query{server} = uc $source_name;
282 14 $self->{QUERY} = { post_process_query(%query) };
283  
284 14 return $self->{QUERY};
285 }
286  
287 5 return {};
288 }
289  
290 0 ▶sub default_query ($$) {
Subroutine default_query: not called CC=1 SCAR=6.9
Pod undocumented
291  
292 0 return arin_query(@_);
293 }
294  
295 4 ▶sub ripe_read_query ($$) {
Subroutine ripe_read_query: called CC=7 SCAR=19.8
Pod undocumented
296  
297 4 my ( $sock, $ip ) = @_;
298  
299 4 my %query = ( fullinfo => '' );
300 4 print $sock "-r $ip\n";
301 4 ▶ while (<$sock>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $sock)) 171 4 175
302 171 $query{fullinfo} .= $_;
303 171 ▶ close $sock and return ( permission => 'denied' ) if /ERROR:201/;
Branch: 1 branch
BranchTrueFalseTotal
if /ERROR:201/ 0 171 171
Condition20%1/5
/ERROR:201/ && (close $sock && (return 'permission', 'denied'))
!ll&&!rl&&r
17100
close $sock and return "permission", "denied"
!ll
00
MC/DC0%0/2
/ERROR:201/ && (close $sock && (return 'permission', 'denied'))
/ERROR:201/ close $sock
Truth table33%1/3
A && B
A= /ERROR:201/B= close $sock
ABresult
0X0
100
111
304 171 ▶ next if ( /^(\%|\#)/ || !/\:/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^(\%|\#)/ or not /\:/ 83 88 171
Condition100%3/3
/^(\%|\#)/ or not /\:/
l!l&&r!l&&!r
453888
MC/DC100%2/2
/^(\%|\#)/ or not /\:/
/^(\%|\#)/ not /\:/
Truth table100%3/3
A or not(B)
A= /^(\%|\#)/B= not /\:/
ABresult
1X1
011
000
305 88 s/\s+$//;
306 88 my ( $field, $value ) = split( /:/, $_, 2 );
307 88 $value =~ s/^\s+//;
308 88 ▶ $query{ lc($field) } .= ( $query{ lc($field) } ? ' ' : '' ) . $value;
Branch: 1 branch
BranchTrueFalseTotal
$query{lc $field} ? : 28 60 88
309 }
310 4 close $sock;
311 4 return %query;
312 }
313  
314 4 ▶sub ripe_process_query (%) {
Subroutine ripe_process_query: called CC=12 SCAR=36.9
Pod undocumented
315  
316 4 my %query = @_;
317  
318 4 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if (defined $query{'remarks'} and $query{'remarks'} =~ /The country is really world wide/ or defined $query{'netname'} and $query{'netname'} =~ /IANA-BLK/ or defined $query{'netname'} and $query{'netname'} =~ /AFRINIC-NET-TRANSFERRED/ or defined $query{'country'} and $query{'country'} =~ /world wide/) { } 0 4 4
elsif (not $query{'inet6num'} || $query{'inetnum'}) { } 0 4 4
Condition33%7/21
defined $query{"remarks"} and $query{"remarks"} =~ /The country is really world wide/ or defined $query{"netname"} and $query{"netname"} =~ /IANA-BLK/ or defined $query{"netname"} and $query{"netname"} =~ /AFRINIC-NET-TRANSFERRED/ or defined $query{"country"} and $query{"country"} =~ /world wide/
l!l&&r!l&&!r
004
defined $query{"remarks"} and $query{"remarks"} =~ /The country is really world wide/ or defined $query{"netname"} and $query{"netname"} =~ /IANA-BLK/ or defined $query{"netname"} and $query{"netname"} =~ /AFRINIC-NET-TRANSFERRED/
l!l&&r!l&&!r
004
defined $query{"remarks"} and $query{"remarks"} =~ /The country is really world wide/ or defined $query{"netname"} and $query{"netname"} =~ /IANA-BLK/
l!l&&r!l&&!r
004
defined $query{"remarks"} and $query{"remarks"} =~ /The country is really world wide/
!ll&&!rl&&r
040
defined $query{"netname"} and $query{"netname"} =~ /IANA-BLK/
!ll&&!rl&&r
040
defined $query{"netname"} and $query{"netname"} =~ /AFRINIC-NET-TRANSFERRED/
!ll&&!rl&&r
040
defined $query{"country"} and $query{"country"} =~ /world wide/
!ll&&!rl&&r
040
MC/DC0%0/8
defined $query{"remarks"} and $query{"remarks"} =~ /The country is really world wide/ or defined $query{"netname"} and $query{"netname"} =~ /IANA-BLK/ or defined $query{"netname"} and $query{"netname"} =~ /AFRINIC-NET-TRANSFERRED/ or defined $query{"country"} and $query{"country"} =~ /world wide/
defined $query{"remarks"} $query{"remarks"} =~ /The country is really world wide/ defined $query{"netname"} $query{"netname"} =~ /IANA-BLK/ defined $query{"netname"} $query{"netname"} =~ /AFRINIC-NET-TRANSFERRED/ defined $query{"country"} $query{"country"} =~ /world wide/
Truth table3%1/31
A and B or C and D or E and F or G and H
A= defined $query{"remarks"}B= $query{"remarks"} =~ /The country is really world wide/C= defined $query{"netname"}D= $query{"netname"} =~ /IANA-BLK/E= defined $query{"netname"}F= $query{"netname"} =~ /AFRINIC-NET-TRANSFERRED/G= defined $query{"country"}H= $query{"country"} =~ /world wide/
ABCDEFGHresult
11XXXXXX1
0X11XXXX1
1011XXXX1
0X0X11XX1
0X1011XX1
100X11XX1
101011XX1
0X0X0X111
0X0X10111
0X100X111
0X1010111
100X0X111
100X10111
10100X111
101010111
0X0X0X0X0
0X0X0X100
0X0X100X0
0X0X10100
0X100X0X0
0X100X100
0X10100X0
0X1010100
100X0X0X0
100X0X100
100X100X0
100X10100
10100X0X0
10100X100
1010100X0
101010100
319 ( defined $query{remarks} && $query{remarks} =~ /The country is really world wide/ )
320 || ( defined $query{netname}
321 && $query{netname} =~ /IANA-BLK/ )
322 || ( defined $query{netname}
323 && $query{netname} =~ /AFRINIC-NET-TRANSFERRED/ )
324 || ( defined $query{country}
325 && $query{country} =~ /world wide/ )
326 ) {
327 0 return ();
328 }
329 ▶ elsif ( !$query{inet6num} && !$query{inetnum} ) {
Condition33%1/3
$query{'inet6num'} || $query{'inetnum'}
l!l&&r!l&&!r
040
MC/DC0%0/2
$query{'inet6num'} || $query{'inetnum'}
$query{'inet6num'} $query{'inetnum'}
Truth table33%1/3
A || B
A= $query{'inet6num'}B= $query{'inetnum'}
ABresult
1X1
011
000
330 0 return ();
331 }
332 else {
333 4 $query{permission} = 'allowed';
334 4 ▶ $query{cidr} = [ Net::CIDR::range2cidr( uc( $query{inet6num} || $query{inetnum} ) ) ];
Condition33%1/3
$query{'inet6num'} || $query{'inetnum'}
l!l&&r!l&&!r
040
MC/DC0%0/2
$query{'inet6num'} || $query{'inetnum'}
$query{'inet6num'} $query{'inetnum'}
Truth table33%1/3
A || B
A= $query{'inet6num'}B= $query{'inetnum'}
ABresult
1X1
011
000
335 }
336 4 return %query;
337 }
338  
339 4 ▶sub ripe_query ($$) {
Subroutine ripe_query: called CC=2 SCAR=7.0
Pod undocumented
340 4 my ( $sock, $ip ) = @_;
341  
342 4 my %query = ripe_read_query( $sock, $ip );
343 4 ▶ return () unless defined $query{country};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $query{"country"} 0 4 4
344 4 return ripe_process_query(%query);
345 }
346  
347 5 ▶sub apnic_read_query ($$) {
Subroutine apnic_read_query: called CC=15 SCAR=27.7
Pod undocumented
348 5 my ( $sock, $ip ) = @_;
349  
350 5 my %query = ( fullinfo => '' );
351 5 my %tmp;
352 5 print $sock "-r $ip\n";
353 5 my $skip_block = 0;
354 5 ▶ while (<$sock>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $sock)) 201 5 206
355 201 $query{fullinfo} .= $_;
356 201 ▶ close $sock and return ( permission => 'denied' ) if /^\%201/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\%201/ 0 201 201
Condition20%1/5
/^\%201/ && (close $sock && (return 'permission', 'denied'))
!ll&&!rl&&r
20100
close $sock and return "permission", "denied"
!ll
00
MC/DC0%0/2
/^\%201/ && (close $sock && (return 'permission', 'denied'))
/^\%201/ close $sock
Truth table33%1/3
A && B
A= /^\%201/B= close $sock
ABresult
0X0
100
111
357 201 ▶ if (m{^\%}) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\%/) 33 168 201
358  
359 # Always skip 0.0.0.0 data
360 # It looks like:
361 # % Information related to '0.0.0.0 - 255.255.255.255'
362 33 ▶ if (m{^\%.*0\.0\.0\.0\s+}) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\%.*0\.0\.0\.0\s+/) 0 33 33
363 0 $skip_block = 1;
364 0 next;
365 }
366 33 $skip_block = 0;
367 33 next;
368 }
369 168 ▶ next if $skip_block;
Branch: 1 branch
BranchTrueFalseTotal
if $skip_block 0 168 168
370 168 ▶ next if ( !/\:/ );
Branch: 1 branch
BranchTrueFalseTotal
unless /\:/ 44 124 168
371 124 s/\s+$//;
372 124 my ( $field, $value ) = split( /:/, $_, 2 );
373 124 $value =~ s/^\s+//;
374 124 ▶ if ( $field =~ /^inet6?num$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^inet6?num$/) 6 118 124
375 6 ▶ next if $value =~ m{0\.0\.0\.0\s+};
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /0\.0\.0\.0\s+/ 0 6 6
376 6 %tmp = %query;
377 6 %query = ();
378 6 $query{fullinfo} = $tmp{fullinfo};
379 }
380 124 my $lc_field = lc($field);
381 124 ▶ next if $lc_field eq 'country' && defined $query{$lc_field};
Branch: 1 branch
BranchTrueFalseTotal
if $lc_field eq "country" and defined $query{$lc_field} 1 123 124
Condition100%3/3
$lc_field eq "country" and defined $query{$lc_field}
!ll&&!rl&&r
11761
MC/DC100%2/2
$lc_field eq "country" and defined $query{$lc_field}
$lc_field eq "country" defined $query{$lc_field}
Truth table100%3/3
A and B
A= $lc_field eq "country"B= defined $query{$lc_field}
ABresult
0X0
100
111
382 123 ▶ $query{$lc_field} .= ( $query{$lc_field} ? ' ' : '' ) . $value;
Branch: 1 branch
BranchTrueFalseTotal
$query{$lc_field} ? : 36 87 123
383 }
384 5 close $sock;
385 5 for ( keys %tmp ) {
386 17 ▶ $query{$_} = $tmp{$_} if !defined $query{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $query{$_} 3 14 17
387 }
388 5 return %query;
389 }
390  
391 3 ▶sub apnic_process_query (%) {
Subroutine apnic_process_query: called CC=8 SCAR=27.7
Pod undocumented
392 3 my %query = @_;
393  
394 3 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if (defined $query{'remarks'} and $query{'remarks'} =~ /address range is not administered by APNIC|This network in not allocated/ or defined $query{'descr'} and $query{'descr'} =~ /not allocated to|by APNIC|placeholder reference/i) { } 0 3 3
elsif (not $query{'inet6num'} || $query{'inetnum'}) { } 0 3 3
Condition44%4/9
defined $query{"remarks"} and $query{"remarks"} =~ /address range is not administered by APNIC|This network in not allocated/ or defined $query{"descr"} and $query{"descr"} =~ /not allocated to|by APNIC|placeholder reference/i
l!l&&r!l&&!r
003
defined $query{"remarks"} and $query{"remarks"} =~ /address range is not administered by APNIC|This network in not allocated/
!ll&&!rl&&r
120
defined $query{"descr"} and $query{"descr"} =~ /not allocated to|by APNIC|placeholder reference/i
!ll&&!rl&&r
030
MC/DC0%0/4
defined $query{"remarks"} and $query{"remarks"} =~ /address range is not administered by APNIC|This network in not allocated/ or defined $query{"descr"} and $query{"descr"} =~ /not allocated to|by APNIC|placeholder reference/i
defined $query{"remarks"} $query{"remarks"} =~ /address range is not administered by APNIC|This network in not allocated/ defined $query{"descr"} $query{"descr"} =~ /not allocated to|by APNIC|placeholder reference/i
Truth table28%2/7
A and B or C and D
A= defined $query{"remarks"}B= $query{"remarks"} =~ /address range is not administered by APNIC|This network in not allocated/C= defined $query{"descr"}D= $query{"descr"} =~ /not allocated to|by APNIC|placeholder reference/i
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
395 ( defined $query{remarks} && $query{remarks} =~ /address range is not administered by APNIC|This network in not allocated/ )
396 || ( defined $query{descr}
397 && $query{descr} =~ /not allocated to|by APNIC|placeholder reference/i )
398 ) {
399 0 return ();
400 }
401 ▶ elsif ( !$query{inet6num} && !$query{inetnum} ) {
Condition33%1/3
$query{'inet6num'} || $query{'inetnum'}
l!l&&r!l&&!r
030
MC/DC0%0/2
$query{'inet6num'} || $query{'inetnum'}
$query{'inet6num'} $query{'inetnum'}
Truth table33%1/3
A || B
A= $query{'inet6num'}B= $query{'inetnum'}
ABresult
1X1
011
000
402 0 return ();
403 }
404 else {
405 3 $query{permission} = 'allowed';
406 3 ▶ $query{cidr} = [ Net::CIDR::range2cidr( uc( $query{inet6num} || $query{inetnum} ) ) ];
Condition33%1/3
$query{'inet6num'} || $query{'inetnum'}
l!l&&r!l&&!r
030
MC/DC0%0/2
$query{'inet6num'} || $query{'inetnum'}
$query{'inet6num'} $query{'inetnum'}
Truth table33%1/3
A || B
A= $query{'inet6num'}B= $query{'inetnum'}
ABresult
1X1
011
000
407 }
408  
409 3 return %query;
410 }
411  
412 3 ▶sub apnic_query ($$) {
Subroutine apnic_query: called CC=1 SCAR=0.0
Pod undocumented
413 3 my ( $sock, $ip ) = @_;
414  
415 3 my %query = apnic_read_query( $sock, $ip );
416 3 return apnic_process_query(%query);
417 }
418  
419 3 ▶sub arin_read_query ($$) {
Subroutine arin_read_query: called CC=13 SCAR=26.2
Pod undocumented
420 3 my ( $sock, $ip ) = @_;
421  
422 3 my %query = ( fullinfo => '' );
423 3 my %tmp = ();
424  
425 3 print $sock "+ $ip\n";
426 3 ▶ while (<$sock>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $sock)) 265 3 268
427 265 $query{fullinfo} .= $_;
428 265 ▶ close $sock and return ( permission => 'denied' ) if /^\#201/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\#201/ 0 265 265
Condition20%1/5
/^\#201/ && (close $sock && (return 'permission', 'denied'))
!ll&&!rl&&r
26500
close $sock and return "permission", "denied"
!ll
00
MC/DC0%0/2
/^\#201/ && (close $sock && (return 'permission', 'denied'))
/^\#201/ close $sock
Truth table33%1/3
A && B
A= /^\#201/B= close $sock
ABresult
0X0
100
111
429 265 ▶ return () if /no match found for/i;
Branch: 1 branch
BranchTrueFalseTotal
if /no match found for/i 0 265 265
430 265 ▶ next if ( /^\#/ || !/\:/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^\#/ or not /\:/ 117 148 265
Condition100%3/3
/^\#/ or not /\:/
l!l&&r!l&&!r
7245148
MC/DC100%2/2
/^\#/ or not /\:/
/^\#/ not /\:/
Truth table100%3/3
A or not(B)
A= /^\#/B= not /\:/
ABresult
1X1
011
000
431 148 s/\s+$//;
432 148 my ( $field, $value ) = split( /:/, $_, 2 );
433 148 $value =~ s/^\s+//;
434 148 ▶ if ( $field eq 'OrgName'
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "OrgName" or $field eq "CustName") 3 145 148
Condition66%2/3
$field eq "OrgName" or $field eq "CustName"
l!l&&r!l&&!r
30145
MC/DC50%1/2
$field eq "OrgName" or $field eq "CustName"
$field eq "OrgName" $field eq "CustName"
Truth table66%2/3
A or B
A= $field eq "OrgName"B= $field eq "CustName"
ABresult
1X1
011
000
435 || $field eq 'CustName' ) {
436 3 %tmp = %query;
437 3 %query = ();
438 3 $query{fullinfo} = $tmp{fullinfo};
439 }
440 148 ▶ $query{ lc($field) } .= ( $query{ lc($field) } ? ' ' : '' ) . $value;
Branch: 1 branch
BranchTrueFalseTotal
$query{lc $field} ? : 34 114 148
441 }
442 3 close $sock;
443  
444 3 ▶ $query{orgname} = $query{custname} if defined $query{custname};
Branch: 1 branch
BranchTrueFalseTotal
if defined $query{"custname"} 0 3 3
445  
446 3 for ( keys %tmp ) {
447 39 ▶ $query{$_} = $tmp{$_} unless defined $query{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $query{$_} 25 14 39
448 }
449  
450 3 return %query;
451 }
452  
453 3 ▶sub arin_process_query (%) {
Subroutine arin_process_query: called CC=5 SCAR=16.1
Pod undocumented
454 3 my %query = @_;
455  
456 return ()
457 3 ▶ if $query{orgid} && $query{orgid} =~ /^\s*RIPE|LACNIC|APNIC|AFRINIC\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $query{"orgid"} and $query{"orgid"} =~ /^\s*RIPE|LACNIC|APNIC|AFRINIC\s*$/ 1 2 3
Condition66%2/3
$query{"orgid"} and $query{"orgid"} =~ /^\s*RIPE|LACNIC|APNIC|AFRINIC\s*$/
!ll&&!rl&&r
021
MC/DC50%1/2
$query{"orgid"} and $query{"orgid"} =~ /^\s*RIPE|LACNIC|APNIC|AFRINIC\s*$/
$query{"orgid"} $query{"orgid"} =~ /^\s*RIPE|LACNIC|APNIC|AFRINIC\s*$/
Truth table66%2/3
A and B
A= $query{"orgid"}B= $query{"orgid"} =~ /^\s*RIPE|LACNIC|APNIC|AFRINIC\s*$/
ABresult
0X0
100
111
458  
459 2 $query{permission} = 'allowed';
460 2 $query{descr} = $query{orgname};
461 2 $query{remarks} = $query{comment};
462 2 $query{status} = $query{nettype};
463 2 $query{inetnum} = $query{netrange};
464 2 $query{source} = 'ARIN';
465 2 ▶ if ( defined $query{cidr} && $query{cidr} =~ /\,/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $query{'cidr'} and $query{'cidr'} =~ /\,/) { } 1 1 2
Condition66%2/3
defined $query{"cidr"} and $query{"cidr"} =~ /\,/
!ll&&!rl&&r
011
MC/DC50%1/2
defined $query{"cidr"} and $query{"cidr"} =~ /\,/
defined $query{"cidr"} $query{"cidr"} =~ /\,/
Truth table66%2/3
A and B
A= defined $query{"cidr"}B= $query{"cidr"} =~ /\,/
ABresult
0X0
100
111
466 1 $query{cidr} = [ split( /\s*\,\s*/, $query{cidr} ) ];
467 }
468 else {
469 1 $query{cidr} = [ $query{cidr} ];
470 }
471  
472 2 return %query;
473 }
474  
475 3 ▶sub arin_query ($$) {
Subroutine arin_query: called CC=1 SCAR=0.0
Pod undocumented
476 3 my ( $sock, $ip ) = @_;
477  
478 3 my %query = arin_read_query( $sock, $ip );
479  
480 3 return arin_process_query(%query);
481 }
482  
483 3 ▶sub lacnic_read_query ($$) {
Subroutine lacnic_read_query: called CC=15 SCAR=30.1
Pod undocumented
484 3 my ( $sock, $ip ) = @_;
485  
486 3 my %query = ( fullinfo => '' );
487  
488 3 print $sock "$ip\n";
489  
490 3 ▶ while (<$sock>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $sock)) 172 3 175
491 172 $query{fullinfo} .= $_;
492 172 ▶ close $sock
Branch: 1 branch
BranchTrueFalseTotal
if /^\%201/ or /^\% Query rate limit exceeded/ or /^\% Not assigned to LACNIC/ or /\% Permission denied/ 0 172 172
Condition28%4/14
(/^\%201/ || /^\% Query rate limit exceeded/ || /^\% Not assigned to LACNIC/ || /\% Permission denied/) && (close $sock && (return 'permission', 'denied'))
!ll&&!rl&&r
17200
/^\%201/ or /^\% Query rate limit exceeded/ or /^\% Not assigned to LACNIC/ or /\% Permission denied/
l!l&&r!l&&!r
00172
/^\%201/ or /^\% Query rate limit exceeded/ or /^\% Not assigned to LACNIC/
l!l&&r!l&&!r
00172
/^\%201/ or /^\% Query rate limit exceeded/
l!l&&r!l&&!r
00172
close $sock and return "permission", "denied"
!ll
00
MC/DC0%0/5
(/^\%201/ || /^\% Query rate limit exceeded/ || /^\% Not assigned to LACNIC/ || /\% Permission denied/) && (close $sock && (return 'permission', 'denied'))
/^\%201/ /^\% Query rate limit exceeded/ /^\% Not assigned to LACNIC/ /\% Permission denied/ close $sock
Truth table11%1/9
A or B or C or D && E
A= /^\%201/B= /^\% Query rate limit exceeded/C= /^\% Not assigned to LACNIC/D= /\% Permission denied/E= close $sock
ABCDEresult
0000X0
1XXX00
01XX00
001X00
000100
1XXX11
01XX11
001X11
000111
493 and return ( permission => 'denied' )
494 if /^\%201/ || /^\% Query rate limit exceeded/ || /^\% Not assigned to LACNIC/ || /\% Permission denied/;
495 172 ▶ if (/^\% (\S+) resource:/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\% (\S+) resource:/) 2 170 172
496 2 my $srv = $1;
497 2 ▶ close $sock and return () if $srv !~ /lacnic|brazil/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $srv =~ /lacnic|brazil/i 0 2 2
Condition20%1/5
$srv =~ /lacnic|brazil/i || close $sock && (return ())
l!l&&r!l&&!r
200
close $sock and return ()
!ll
00
MC/DC0%0/2
$srv =~ /lacnic|brazil/i || close $sock && (return ())
$srv =~ /lacnic|brazil/i close $sock
Truth table33%1/3
A || B
A= $srv =~ /lacnic|brazil/iB= close $sock
ABresult
1X1
011
000
498 }
499 172 ▶ next if ( /^\%/ || !/\:/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^\%/ or not /\:/ 61 111 172
Condition100%3/3
/^\%/ or not /\:/
l!l&&r!l&&!r
3823111
MC/DC100%2/2
/^\%/ or not /\:/
/^\%/ not /\:/
Truth table100%3/3
A or not(B)
A= /^\%/B= not /\:/
ABresult
1X1
011
000
500 111 s/\s+$//;
501 111 my ( $field, $value ) = split( /:/, $_, 2 );
502 111 $value =~ s/^\s+//;
503 111 ▶ next if $field eq 'country' && $query{country};
Branch: 1 branch
BranchTrueFalseTotal
if $field eq "country" and $query{"country"} 4 107 111
Condition100%3/3
$field eq "country" and $query{"country"}
!ll&&!rl&&r
10524
MC/DC100%2/2
$field eq "country" and $query{"country"}
$field eq "country" $query{"country"}
Truth table100%3/3
A and B
A= $field eq "country"B= $query{"country"}
ABresult
0X0
100
111
504 107 ▶ $query{ lc($field) } .= ( $query{ lc($field) } ? ' ' : '' ) . $value;
Branch: 1 branch
BranchTrueFalseTotal
$query{lc $field} ? : 47 60 107
505 }
506 3 close $sock;
507 3 return %query;
508 }
509  
510 3 ▶sub lacnic_process_query (%) {
Subroutine lacnic_process_query: called CC=7 SCAR=21.5
Pod undocumented
511 3 my %query = @_;
512  
513 3 $query{permission} = 'allowed';
514 3 $query{descr} = $query{owner};
515 3 $query{netname} = $query{ownerid};
516 3 $query{source} = 'LACNIC';
517 3 ▶ if ( $query{inetnum} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($query{"inetnum"}) 3 0 3
518 3 $query{cidr} = $query{inetnum};
519 3 $query{inetnum} = ( Net::CIDR::cidr2range( $query{cidr} ) )[0];
520 }
521 3 ▶ unless ( $query{country} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query{"country"}) 1 2 3
522 1 ▶ if ( $query{nserver} && $query{nserver} =~ /\.(\w\w)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($query{'nserver'} and $query{'nserver'} =~ /\.(\w\w)$/) { } 0 1 1
elsif ($query{'descr'} and $query{'descr'} =~ /\s(\w\w)$/) { } 0 1 1
Condition33%1/3
$query{"nserver"} and $query{"nserver"} =~ /\.(\w\w)$/
!ll&&!rl&&r
010
MC/DC0%0/2
$query{"nserver"} and $query{"nserver"} =~ /\.(\w\w)$/
$query{"nserver"} $query{"nserver"} =~ /\.(\w\w)$/
Truth table33%1/3
A and B
A= $query{"nserver"}B= $query{"nserver"} =~ /\.(\w\w)$/
ABresult
0X0
100
111
523 0 $query{country} = uc $1;
524 }
525 ▶ elsif ( $query{descr} && $query{descr} =~ /\s(\w\w)$/ ) {
Condition33%1/3
$query{"descr"} and $query{"descr"} =~ /\s(\w\w)$/
!ll&&!rl&&r
010
MC/DC0%0/2
$query{"descr"} and $query{"descr"} =~ /\s(\w\w)$/
$query{"descr"} $query{"descr"} =~ /\s(\w\w)$/
Truth table33%1/3
A and B
A= $query{"descr"}B= $query{"descr"} =~ /\s(\w\w)$/
ABresult
0X0
100
111
526 0 $query{country} = uc $1;
527 }
528 else {
529 1 return ();
530 }
531 }
532 2 return %query;
533 }
534  
535 3 ▶sub lacnic_query ($$) {
Subroutine lacnic_query: called CC=1 SCAR=0.0
Pod undocumented
536 3 my ( $sock, $ip ) = @_;
537  
538 3 my %query = lacnic_read_query( $sock, $ip );
539  
540 3 return lacnic_process_query(%query);
541 }
542  
543 10 *afrinic_read_query = *apnic_read_query;
544  
545 2 ▶sub afrinic_process_query (%) {
Subroutine afrinic_process_query: called CC=8 SCAR=27.7
Pod undocumented
546 2 my %query = @_;
547  
548 return ()
549 if defined $query{remarks} && $query{remarks} =~ /country is really worldwide/
550 2 ▶ or defined $query{descr} && $query{descr} =~ /Here for in-addr\.arpa authentication/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $query{"remarks"} and $query{"remarks"} =~ /country is really worldwide/ or defined $query{"descr"} and $query{"descr"} =~ /Here for in-addr\.arpa authentication/ 0 2 2
Condition33%3/9
defined $query{"remarks"} and $query{"remarks"} =~ /country is really worldwide/ or defined $query{"descr"} and $query{"descr"} =~ /Here for in-addr\.arpa authentication/
l!l&&r!l&&!r
002
defined $query{"remarks"} and $query{"remarks"} =~ /country is really worldwide/
!ll&&!rl&&r
200
defined $query{"descr"} and $query{"descr"} =~ /Here for in-addr\.arpa authentication/
!ll&&!rl&&r
020
MC/DC0%0/4
defined $query{"remarks"} and $query{"remarks"} =~ /country is really worldwide/ or defined $query{"descr"} and $query{"descr"} =~ /Here for in-addr\.arpa authentication/
defined $query{"remarks"} $query{"remarks"} =~ /country is really worldwide/ defined $query{"descr"} $query{"descr"} =~ /Here for in-addr\.arpa authentication/
Truth table14%1/7
A and B or C and D
A= defined $query{"remarks"}B= $query{"remarks"} =~ /country is really worldwide/C= defined $query{"descr"}D= $query{"descr"} =~ /Here for in-addr\.arpa authentication/
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
551  
552 2 ▶ if ( !$query{inet6num} && !$query{inetnum} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query{"inet6num"} or $query{"inetnum"}) 0 2 2
Condition33%1/3
$query{"inet6num"} or $query{"inetnum"}
l!l&&r!l&&!r
020
MC/DC0%0/2
$query{"inet6num"} or $query{"inetnum"}
$query{"inet6num"} $query{"inetnum"}
Truth table33%1/3
A or B
A= $query{"inet6num"}B= $query{"inetnum"}
ABresult
1X1
011
000
553 0 return ();
554 }
555  
556 2 $query{permission} = 'allowed';
557 $query{cidr} =
558 2 ▶ [ Net::CIDR::range2cidr( uc( $query{inet6num} || $query{inetnum} ) ) ];
Condition33%1/3
$query{'inet6num'} || $query{'inetnum'}
l!l&&r!l&&!r
020
MC/DC0%0/2
$query{'inet6num'} || $query{'inetnum'}
$query{'inet6num'} $query{'inetnum'}
Truth table33%1/3
A || B
A= $query{'inet6num'}B= $query{'inetnum'}
ABresult
1X1
011
000
559 2 return %query;
560 }
561  
562 2 ▶sub afrinic_query ($$) {
Subroutine afrinic_query: called CC=1 SCAR=0.0
Pod undocumented
563 2 my ( $sock, $ip ) = @_;
564  
565 2 my %query = afrinic_read_query( $sock, $ip );
566  
567 2 return afrinic_process_query(%query);
568 }
569  
570 4 ▶sub is_mine ($$;@) {
Subroutine is_mine: called CC=4 SCAR=13.9
Pod documented
571 4 my ( $self, $ip, @cidr ) = @_;
572  
573 4 ▶ return 0 unless is_valid_ip($ip);
Branch: 1 branch
BranchTrueFalseTotal
unless &is_valid_ip($ip) 0 4 4
574 4 ▶ if ( !scalar @cidr ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @cidr) 2 2 4
575 2 my $out = $self->cidr();
576 2 ▶ @cidr = @$out if ref $out;
Branch: 1 branch
BranchTrueFalseTotal
if ref $out 2 0 2
577 }
578  
579 @cidr = map {
580 4 my @dots = ( split /\./ );
581 4 my $pad = '.0' x ( 4 - @dots );
582 4 s|(/.*)|$pad$1|;
583 4 $_;
584 }
585 4 map { split(/\s+/) }
586 4 grep { defined $_ } @cidr;
587  
588 4 return Net::CIDR::cidrlookup( $ip, @cidr );
589 }
590  
591 10 1;
592  
593 __END__
↑ Summary