line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NetAddr::IP::Obfuscate; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.006_000; # Needed for NetAddr::IP and the $fh in _slurp_file |
4
|
1
|
|
|
1
|
|
61754
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION @EXPORT); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
95
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = '0.02'; |
13
|
|
|
|
|
|
|
@EXPORT = qw(do_obfu); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
93
|
|
16
|
1
|
|
|
1
|
|
880
|
use NetAddr::IP::Find; |
|
1
|
|
|
|
|
44390
|
|
|
1
|
|
|
|
|
397
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub do_obfu { |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
|
my %obfuscated; |
21
|
|
|
|
|
|
|
my $infile; |
22
|
0
|
|
|
|
|
|
my $net; |
23
|
0
|
|
|
|
|
|
my $outfile; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
if (scalar(@_) == 0) { |
26
|
|
|
|
|
|
|
# No arguments, supply some sane defaults |
27
|
0
|
|
|
|
|
|
$infile = "-"; |
28
|
0
|
|
|
|
|
|
$net = "10.0.0.0/8"; |
29
|
0
|
|
|
|
|
|
$outfile = "STDOUT"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} else { |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
($infile,$net,$outfile) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $text_ref = _slurp_file ($infile); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $ip = NetAddr::IP->new("$net"); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
find_ipaddrs($$text_ref, sub { |
43
|
0
|
|
|
0
|
|
|
my($ipaddr, $orig) = @_; |
44
|
0
|
0
|
|
|
|
|
return $obfuscated{$orig} if exists $obfuscated{$orig}; |
45
|
0
|
|
|
|
|
|
++$ip; |
46
|
0
|
|
|
|
|
|
$obfuscated{$orig} = $ip->addr; |
47
|
0
|
|
|
|
|
|
}); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
_burp_file ($outfile, $text_ref); |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
return values %obfuscated if wantarray(); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return scalar(keys %obfuscated); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _slurp_file { |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
0
|
|
|
my $infile = shift; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
open( my $fh, $infile ) or croak "Unable to open $infile in _slurp_file: $!\n"; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $text = do { local( $/ ) ; <$fh> } ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return \$text; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _burp_file { |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
|
|
my $outfile = shift; |
73
|
0
|
|
|
|
|
|
my $text_ref = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if ($outfile eq "STDOUT") { |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
print $$text_ref; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} else { |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
open( my $fh, ">$outfile" ) or croak "Unable to open $outfile in _burp_file: $!\n" ; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
print $fh $$text_ref ; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |