I can get you started. This is a script i use on my site to ban bad bots but can be modified to suit your needs. First create a cgi file named trap.pl and add this script to it and chmod 755:
Code:
#!/usr/bin/perl -w
# This is the only variable that needs to be modified.
# Replace it with the absolute path to your root directory.
$rootdir = "/home/byron/public_html/";
# Grab the IP of the bad bot
$visitor_ip = $ENV{'REMOTE_ADDR'};
$visitor_ip =~ s/\./\\\./gi;
# Open .htaccess file
open(HTACCESS,"".$rootdir."/\.htaccess") || die $!;
@htaccess = <HTACCESS>;
close(HTACCESS);
# Write banned IP to .htaccess file
open(HTACCESS,">".$rootdir."/\.htaccess") || die $!;
print HTACCESS "SetEnvIf Remote_Addr \^".$visitor_ip."\$ ban\n";
foreach $deny_ip (@htaccess) {
print HTACCESS $deny_ip;
}
close(HTACCESS);
# Close
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>Access Denied!</title>\n";
print "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
print "</head>\n";
print "<body>\n";
print "<p><b>Access Denied!</b></p>\n";
print "</body>\n";
print "</html>\n";
exit;
Then add this to the top of your root htaccess file:
Code:
SetEnvIf Remote_Addr ^65\.29\.81\.103$ ban
order allow,deny
allow from all
deny from env=ban
Here are a couple of simple ways to auto ban an IP.
1. As a simple hyperlink:
http://www.yourdomain.com/cgi-bin/trap.pl
2. In your case you could write a php or perl/cgi script as your 404 page to check if a certain ip has hit the page more than 5 times. Once it is hit 5 times then show trap.pl and the bad ip is written to your htaccess file.
How it works.
Every time a user hits trap.pl their IP is written to the top of the .htaccess file. Your .htaccess file will begin to look something like this:
Code:
SetEnvIf Remote_Addr ^65\.29\.81\.103$ ban
SetEnvIf Remote_Addr ^201\.44\.73\.40$ ban
SetEnvIf Remote_Addr ^306\.90\.74\.60$ ban
order allow,deny
allow from all
deny from env=ban
If your not familiar enough with php or perl/cgi, you could ask in the those forums for help.