So, say you have some logs in a file called logfile that contain IP addresses and you'd like to anonymize them and be able to publish the anonymized version of the logs. You could do something like this:
./anonymize-logs logfile
Where anonymize-logs looks something like this (be sure to change the 32 values in @key to random values between 0 to 255, this becomes your private key):
#!/usr/bin/perl -wT
use strict;
$|=1;
use IP::Anonymous;
my @key = (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);
my $obj = new IP::Anonymous(@key);
while(defined(my $line=<>)) {
chomp $line;
if($line =~ /\d{1,3}(?:\.\d{1,3}){3}/) {
$line =~
s/(\d{1,3}(?:\.\d{1,3}){3})/$obj->anonymize($1)/eg;
}
print $line."\n";
}
John |