DNSBLLookup.pm

filter: Statementstmt 64.2% 63 / 98 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 90.4% 19 / 21 Podpod 100% 2 / 2 totaltotal 62.6% 84 / 134 CC 10 SCAR 30.5
CC
10
Cov
57%
lookup
72.0
new
12.0
BEGIN
1.0
CRAP 21.0
« DNSBLLookup/Result.pm ↑ Summary
1 package Net::DNSBLLookup;
2  
3 1 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require Exporter;
7 1 ▶use vars qw($VERSION @EXPORT @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Net::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 $VERSION = '0.05';
11 1 @ISA = qw(Exporter);
12  
13 1 @EXPORT = qw(DNSBLLOOKUP_OPEN_RELAY DNSBLLOOKUP_DYNAMIC_IP
14 DNSBLLOOKUP_CONFIRMED_SPAM DNSBLLOOKUP_SMARTHOST DNSBLLOOKUP_SPAMHOUSE DNSBLLOOKUP_LISTSERVER
15 DNSBLLOOKUP_FORMMAIL DNSBLLOOKUP_OPEN_PROXY DNSBLLOOKUP_OPEN_PROXY_HTTP DNSBLLOOKUP_OPEN_PROXY_SOCKS
16 DNSBLLOOKUP_OPEN_PROXY_MISC DNSBLLOOKUP_HIJACKED DNSBLLOOKUP_MULTI_OPEN_RELAY DNSBLLOOKUP_UNKNOWN);
17  
18 1 ▶use constant DNSBLLOOKUP_OPEN_RELAY => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use constant DNSBLLOOKUP_DYNAMIC_IP => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use constant DNSBLLOOKUP_CONFIRMED_SPAM => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use constant DNSBLLOOKUP_SMARTHOST => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use constant DNSBLLOOKUP_SPAMHOUSE => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use constant DNSBLLOOKUP_LISTSERVER => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use constant DNSBLLOOKUP_FORMMAIL => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use constant DNSBLLOOKUP_OPEN_PROXY => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use constant DNSBLLOOKUP_OPEN_PROXY_HTTP => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use constant DNSBLLOOKUP_OPEN_PROXY_SOCKS => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use constant DNSBLLOOKUP_OPEN_PROXY_MISC => 11;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use constant DNSBLLOOKUP_HIJACKED => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use constant DNSBLLOOKUP_MULTI_OPEN_RELAY => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use constant DNSBLLOOKUP_UNKNOWN => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 require Net::DNSBLLookup::Result;
34  
35 1 %Net::DNSBLLookup::dns_servers = (
36  
37 # no longer implemented, since osirusoft.com was taken offline due
38 # to DDos attacks from spammers
39  
40 # 'relays.osirusoft.com' => {
41 # '127.0.0.2' => DNSBLLOOKUP_OPEN_RELAY,
42 # '127.0.0.3' => DNSBLLOOKUP_DYNAMIC_IP, # dialup
43 # '127.0.0.4' => DNSBLLOOKUP_CONFIRMED_SPAM,
44 # '127.0.0.5' => DNSBLLOOKUP_SMARTHOST,
45 # '127.0.0.6' => DNSBLLOOKUP_SPAMHOUSE,
46 # '127.0.0.7' => DNSBLLOOKUP_LISTSERVER,
47 # '127.0.0.8' => DNSBLLOOKUP_FORMMAIL,
48 # '127.0.0.9' => DNSBLLOOKUP_OPEN_PROXY,
49 # },
50 'dnsbl.sorbs.net' => {
51 '127.0.0.2' => DNSBLLOOKUP_OPEN_PROXY_HTTP,
52 '127.0.0.3' => DNSBLLOOKUP_OPEN_PROXY_SOCKS,
53 '127.0.0.4' => DNSBLLOOKUP_OPEN_PROXY_MISC,
54 '127.0.0.5' => DNSBLLOOKUP_OPEN_RELAY,
55 '127.0.0.6' => DNSBLLOOKUP_SPAMHOUSE,
56 '127.0.0.7' => DNSBLLOOKUP_FORMMAIL,
57 '127.0.0.8' => DNSBLLOOKUP_CONFIRMED_SPAM,
58 '127.0.0.9' => DNSBLLOOKUP_HIJACKED,
59 '127.0.0.10' => DNSBLLOOKUP_DYNAMIC_IP, # not same as dialup
60 },
61 'proxies.blackholes.easynet.net' => {
62 '127.0.0.2' => DNSBLLOOKUP_OPEN_PROXY,
63 },
64 'dnsbl.njabl.org' => {
65 '127.0.0.2' => DNSBLLOOKUP_OPEN_RELAY,
66 '127.0.0.3' => DNSBLLOOKUP_DYNAMIC_IP,
67 '127.0.0.4' => DNSBLLOOKUP_SPAMHOUSE,
68 '127.0.0.5' => DNSBLLOOKUP_MULTI_OPEN_RELAY,
69 '127.0.0.8' => DNSBLLOOKUP_FORMMAIL,
70 '127.0.0.9' => DNSBLLOOKUP_OPEN_PROXY,
71 },
72 # 'list.dsbl.org' => {
73 # '127.0.0.2' => DNSBLLOOKUP_UNKNOWN,
74 # },
75 # 'opm.blitzed.org' => sub {
76 # my ($ip) = @_;
77 # # todo deal with bitmasks properly
78 # # see http://opm.blitzed.org/info
79 # return DNSBLLOOKUP_OPEN_PROXY;
80 # },
81 'cbl.abuseat.org' => {
82 '127.0.0.2' => DNSBLLOOKUP_OPEN_PROXY,
83 },
84 'psbl.surriel.com' => {
85 '127.0.0.2' => DNSBLLOOKUP_OPEN_PROXY,
86 },
87 );
88  
89 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
90 0 my ($class) = shift;
91 0 my $self = { @_ };
92 0 bless $self, $class;
93 0 ▶ unless (exists $self->{zones}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"zones"}) 0 0 0
94 0 @{$self->{zones}} = grep !/^relays\.osirusoft\.com$/, keys %Net::DNSBLLookup::dns_servers;
95 }
96 0 ▶ $self->{timeout} ||= 5;
Condition0%0/2
$self->{"timeout"} ||= 5
l!l
00
MC/DC0%0/1
$self->{"timeout"} ||= 5
$self->{"timeout"}
Truth table0%0/2
A
A= $self->{"timeout"}
Aresult
11
00
97 0 return $self;
98 }
99  
100 0 ▶sub lookup {
Subroutine lookup: not called CC=8 SCAR=42.8
Pod documented
101 0 my ($self, $ip) = @_;
102  
103 0 my $res = Net::DNS::Resolver->new;
104 0 my $sel = IO::Select->new;
105 0 my @sockets;
106  
107 0 my $result = Net::DNSBLLookup::Result->new();
108  
109 0 my $reverse_ip = join('.',reverse split('\.',$ip));
110  
111 0 for my $zone (@{$self->{zones}}) {
112 0 my $host = join('.',$reverse_ip,$zone);
113 0 my $socket = $res->bgsend($host);
114 0 $sel->add($socket);
115 0 undef $socket;
116 }
117  
118 0 ▶ while ($sel->count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sel->count > 0) 0 0 0
119 0 my @ready = $sel->can_read($self->{timeout});
120 0 ▶ last unless @ready;
Branch: 1 branch
BranchTrueFalseTotal
unless @ready 0 0 0
121 0 foreach my $sock (@ready) {
122 0 my $packet = $res->bgread($sock);
123 0 my ($question) = $packet->question;
124 0 ▶ next unless $question;
Branch: 1 branch
BranchTrueFalseTotal
unless $question 0 0 0
125 0 my $qname = $question->qname;
126 0 (my $dnsbl = $qname) =~ s!^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.!!;
127 0 $result->add_dnsbl($dnsbl);
128 0 foreach my $rr ($packet->answer) {
129 0 ▶ next unless $rr->type eq "A";
Branch: 1 branch
BranchTrueFalseTotal
unless $rr->type eq "A" 0 0 0
130 0 $result->add($dnsbl, $rr->address);
131 }
132 0 $sel->remove($sock);
133 }
134 }
135 0 return $result;
136 }
137  
138 1 1;
139 __END__
« DNSBLLookup/Result.pm ↑ Summary