line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NET::IPFilterSimple; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
35635
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2928
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require Exporter; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
10
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
11
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# This allows declaration use NET::IPFilterSimple ':all'; |
14
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
15
|
|
|
|
|
|
|
# will save memory. |
16
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
17
|
|
|
|
|
|
|
isValid |
18
|
|
|
|
|
|
|
_init |
19
|
|
|
|
|
|
|
) ] ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT = qw( |
24
|
|
|
|
|
|
|
isValid |
25
|
|
|
|
|
|
|
_init |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '1.2'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new(){ |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
34
|
0
|
0
|
|
|
|
|
my %args = ref($_[0])?%{$_[0]}:@_; |
|
0
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $self = \%args; |
36
|
0
|
|
|
|
|
|
bless $self, $class; |
37
|
0
|
|
|
|
|
|
$self->_init(); |
38
|
0
|
|
|
|
|
|
return $self; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
}; # sub new(){ |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub isValid(){ |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
0
|
|
|
|
|
|
my $IPtoCheck = shift; |
47
|
0
|
|
|
|
|
|
my $RangesArrayRef = $self->{'_IPRANGES_ARRAY_REF'}; |
48
|
0
|
|
|
|
|
|
my $howmany = scalar( @{$RangesArrayRef} ); |
|
0
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$IPtoCheck =~ s/\.//g; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
for ( my $count=0; $count<=$howmany; $count++) { |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my ($RangFrom, $RangTo) = split("-", $RangesArrayRef->[$count]); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
0
|
|
|
|
if ( $IPtoCheck >= $RangFrom && $IPtoCheck <= $RangTo ) { |
57
|
0
|
|
|
|
|
|
return 0; |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
}; # for ( my $count=0; $count<=$howmany; $count++) { |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return 1; # if ip not found in ipfilter.dat its valid |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
}; # sub isValid(){ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _init(){ |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
my $file = $self->{'ipfilter'}; |
72
|
0
|
0
|
|
|
|
|
die "$self->_init() - Fatal Error no ipfilter.dat given" if ( length $file < 1 ); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my @IP_Ranges = (); |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
open(RH,"<$file") or die("$self -> _init( $file ) Reading Failed"); |
77
|
0
|
|
|
|
|
|
while (defined( my $entry = )) { |
78
|
0
|
|
|
|
|
|
chomp($entry); |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
0
|
|
|
|
next if ( $entry =~ /^#/g || $entry =~ /#/g ); |
81
|
0
|
|
|
|
|
|
my ($IPRange, undef, $DESC) = split(",", $entry); |
82
|
0
|
0
|
|
|
|
|
next if ( $DESC =~ /\[BG\]FreeSP/ig ); # ignore not used ips |
83
|
0
|
|
|
|
|
|
my ($IP_Start,$IP_End) = split("-", $IPRange ); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$IP_Start =~ s/^\s+//; |
86
|
0
|
|
|
|
|
|
$IP_Start =~ s/\s+$//; |
87
|
0
|
|
|
|
|
|
$IP_End =~ s/^\s+//; |
88
|
0
|
|
|
|
|
|
$IP_End =~ s/\s+$//; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$IP_Start =~ s/\.//g; |
91
|
0
|
|
|
|
|
|
$IP_End =~ s/\.//g; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
push(@IP_Ranges, "$IP_Start-$IP_End"); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
}; # while (defined( my $entry = )) { |
97
|
0
|
|
|
|
|
|
close RH; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$self->{'_IPRANGES_ARRAY_REF'} = \@IP_Ranges; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $self; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
}; # sub _init(){ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Preloaded methods go here. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |