#!/usr/bin/perl
# use File::Pid;
# my $pidfile = File::Pid->new( { file => '/var/run/x0.pid', } );
# my $pid = $pidfile->running;
# die "Service already running: $pid\n" if $pid;
# $pidfile->write;
# # You can uncomment this to script
# # At the same time does not start again
#my $spam = get("http://www.stopforumspam.com/downloads/bannedips.zip");
# system("ipfw table 1 flush > /dev/null &") if (defined $spam);
system("wget http://www.stopforumspam.com/downloads/bannedips.zip");
# use Archive::Zip;
# my $zip = Archive::Zip->new("bannedips.zip");
# $zip->extractTree();
system("/usr/local/bin/unzip bannedips.zip");
open( IPB, "bannedips.csv" );
$/ = ''; # Enable reading paragraphs
my $spam = <IPB>;
close IPB;
system("rm bannedips.csv");
system("rm bannedips.zip");
open( IP, "ipfw table 1 list |" );
$/ = ''; # Enable reading paragraphs
my $use_ip = <IP>;
close IP;
#####################
# IP которые уже приÑутÑтвуют в таблице не удалÑÑŽÑ‚ÑÑ
# а добавлÑÑŽÑ‚ÑÑ Ð½Ð¾Ð²Ñ‹Ðµ тех которых нету
# IP which are already present in the table are not removed
# And add new those who no
my %seen;
@seen{ return_ip($spam) } = ();
delete @seen{ return_ip($use_ip) };
foreach ( keys %seen ) {
print $_;
system( "exec ipfw table 1 add " . $_ );
}
sub return_ip {
my $hash;
$hash->{$1}++
while $_[0] =~ /(\d+\.\d+\.\d+\.\d+)/smg xor
grep { $_ > 255 } split /\./,
$1;
return keys %$hash;
}
# $pidfile->remove;
# # You can uncomment this to script
# # At the same time does not start again
exit;