2 # IP Address block list / checker
4 # This is a DXSpider compatible, optional skin over Net::CIDR::Lite
5 # If Net::CIDR::Lite is not present, then a find will always returns 0
21 our $badipfn = "badip";
31 $count4 = _get($ipv4, 4);
32 $count6 = _get($ipv6, 6);
34 LogDbg('DXProt', "DXCIDR: loaded $count4 IPV4 addresses and $count6 IPV6 addresses");
35 return $count4 + $count6;
40 return localdata($badipfn) . "$_[0]";
48 my $fh = IO::File->new($fn);
59 $list->clean if $count;
61 LogDbg('err', "DXCIDR: $fn not found ($!)");
72 my $fh = IO::File->new (">$fn.$r");
79 LogDbg('err', "DXCIDR: cannot write $fn.$r $!");
86 # protect against stupid or malicious
92 LogDbg('DXProt', "DXCIDR: Added IPV4 $_ address");
96 LogDbg('DXProt', "DXCIDR: Added IPV6 $_ address");
99 if ($ipv4 && $count4) {
103 if ($ipv6 && $count6) {
111 return 0 unless $active;
112 my $list = $ipv4->list;
113 _put($list, 4) if $list;
115 _put($list, 6) if $list;
121 push @out, $ipv4->list;
122 push @out, $ipv6->list;
123 return (1, sort @out);
128 return 0 unless $active;
129 return 0 unless $_[0];
132 return $ipv4->find($_[0]) if $count4;
134 return $ipv6->find($_[0]) if $count6;
139 eval { require Net::CIDR::Lite };
141 LogDbg('DXProt', "DXCIDR: load (cpanm) the perl module Net::CIDR::Lite to check for bad IP addresses (or CIDR ranges)");
145 import Net::CIDR::Lite;
147 $ipv4 = Net::CIDR::Lite->new;
148 $ipv6 = Net::CIDR::Lite->new;