| 1 | package NetAddr::IP::Obfuscate; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | require 5.006_000; # Needed for NetAddr::IP and the $fh in _slurp_file | |||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | require Exporter; | |||||||||
| 7 | |||||||||||
| 8 | 1 | our @ISA = qw(Exporter); | |||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use vars qw($VERSION @EXPORT); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | $VERSION = '0.02'; | |||||||||
| 13 | 1 | @EXPORT = qw(do_obfu); | |||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use NetAddr::IP::Find; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub do_obfu { | ||||||||
|
Subroutine
do_obfu: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 19 | |||||||||||
| 20 | 0 | my %obfuscated; | |||||||||
| 21 | my $infile; | ||||||||||
| 22 | 0 | my $net; | |||||||||
| 23 | 0 | my $outfile; | |||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | if (scalar(@_) == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | find_ipaddrs($$text_ref, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 43 | 0 | my($ipaddr, $orig) = @_; | |||||||||
| 44 | 0 | ▶ | return $obfuscated{$orig} if exists $obfuscated{$orig}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | ++$ip; | |||||||||
| 46 | 0 | $obfuscated{$orig} = $ip->addr; | |||||||||
| 47 | 0 | }); | |||||||||
| 48 | |||||||||||
| 49 | 0 | _burp_file ($outfile, $text_ref); | |||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | return values %obfuscated if wantarray(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 0 | return scalar(keys %obfuscated); | |||||||||
| 54 | |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | sub _slurp_file { | ||||||||
|
Subroutine
_slurp_file: not called CC=2 SCAR=17.9
| |||||||||||
| 59 | |||||||||||
| 60 | 0 | my $infile = shift; | |||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | open( my $fh, $infile ) or croak "Unable to open $infile in _slurp_file: $!\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | |||||||||||
| 64 | 0 | my $text = do { local( $/ ) ; <$fh> } ; | |||||||||
| 65 | |||||||||||
| 66 | 0 | return \$text; | |||||||||
| 67 | |||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | sub _burp_file { | ||||||||
|
Subroutine
_burp_file: not called CC=3 SCAR=24.8
| |||||||||||
| 71 | |||||||||||
| 72 | 0 | my $outfile = shift; | |||||||||
| 73 | 0 | my $text_ref = shift; | |||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | if ($outfile eq "STDOUT") { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | |||||||||||
| 77 | 0 | print $$text_ref; | |||||||||
| 78 | |||||||||||
| 79 | } else { | ||||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | open( my $fh, ">$outfile" ) or croak "Unable to open $outfile in _burp_file: $!\n" ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | |||||||||||
| 83 | 0 | print $fh $$text_ref ; | |||||||||
| 84 | |||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 1 | 1; | |||||||||
| 90 | |||||||||||
| 91 | __END__ | ||||||||||