#!/usr/bin/perl use strict; my $logfile = "/www/log/analyze_log"; my $htaccess = "/www/public_html/.htaccess"; my @hosts = ('isacommie.com', 'musicbox1.com', 'highprofitclub.com', 'nutzu.com', 'doobu.com'); my $end = 31; my %IP; for (my $i = 0; $i <= $end; $i++) { my $file = $logfile . '.' . $i; if ($i == 0) { $file = $logfile; } open (IN, $file); while () { my @d = split(/\t/); if ($d[2] =~ /^http/ && index($d[2], '?') == -1) { foreach my $host (@hosts) { if (index($d[2], $host) != -1) { $IP{$d[1]}++; last; } } } } close (IN); } open (IN, $htaccess); while () { if ($_ =~ /deny from (.*?)\n/) { delete $IP{$1}; } } close (IN); my $deny; foreach my $ip (sort { $a <=> $b } keys %IP) { $deny .= 'deny from ' . $ip . "\n"; } if ($deny) { open (OUT, ">> $htaccess"); print OUT $deny; close (OUT); } exit;