line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NetAddr::IP::Find; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30363
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
129
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @EXPORT); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use base qw(Exporter); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
121
|
|
8
|
|
|
|
|
|
|
@EXPORT = qw(find_ipaddrs); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1210
|
use NetAddr::IP; |
|
1
|
|
|
|
|
68765
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $regex = qr<(\d+)\.(\d+)\.(\d+)\.(\d+)>; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub find_ipaddrs (\$&) { |
15
|
1
|
|
|
1
|
0
|
38
|
my($r_text, $callback) = @_; |
16
|
1
|
|
|
|
|
3
|
my $addrs_found = 0; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
14
|
$$r_text =~ s{$regex}{ |
19
|
7
|
|
|
|
|
103
|
my $orig_match = join '.', $1, $2, $3, $4; |
20
|
7
|
100
|
|
|
|
14
|
if ((my $num_matches = grep { _in_range($_) } $1, $2, $3, $4) == 4) { |
|
28
|
|
|
|
|
44
|
|
21
|
6
|
|
|
|
|
7
|
$addrs_found++; |
22
|
6
|
|
|
|
|
30
|
my $ipaddr = NetAddr::IP->new($orig_match); |
23
|
6
|
|
|
|
|
578
|
$callback->($ipaddr, $orig_match); |
24
|
|
|
|
|
|
|
} else { |
25
|
1
|
|
|
|
|
6
|
$orig_match; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
}eg; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
4
|
return $addrs_found; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _in_range { |
33
|
28
|
|
66
|
28
|
|
160
|
return 0 <= $_[0] && $_[0] <= 255; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
__END__ |