Page is a not externally linkable
- Search Engines
-- Search Engine Spider and User Agent Identification
---- Unknown bot - amzn_assoc


carfac - 4:47 pm on Dec 9, 2002 (gmt 0)


Hi:

I had a few requests, and the script is not a secret, so I decided to post here. Apologies to Key_Master for hacking his script! Comments welcome- thats why we are in this forum, right? Lets make it all better!

OK, here is the script. See instructions AFTER the script!

#!/usr/local/bin/perl
# Name this script trap.pl, upload it in ASCII mode to your cgi-bin and set the file permissions to CHMOD 755.
# Original script by Key_Master taken from [webmasterworld.com...]

# This is the only variable that needs to be modified. Replace it with the absolute path to your root directory.
$rootdir = "/path/to/root/directory";

# Grab the IP of the bad bot
$visitor_ip = $ENV{'REMOTE_ADDR'};

if ($visitor_ip =~ /^216\.239\.3([3¦7¦9]\.5)$¦^216\.239\.35\.4$/) {
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>Forward On</title>\n<META NAME=\"robots\" CONTENT=\"NOINDEX,NOFOLLOW\">\n";
print "</head>\n";
print "<body>\n";
print "<p><b>We had an error.<BR>Please return to continue!</b></p>\n";
print "</body>\n";
print "</html>\n";
exit;
}
else {

$visitor_ip =~ s/\./\\\./gi;

# Set Date
$date = scalar localtime ( time );

# Open .htaccess file
open(HTACCESS,"".$rootdir."/bad_ip.txt") ¦¦ die $!;
@htaccess = <HTACCESS>;
close(HTACCESS);

# Write banned IP to .htaccess file
open(HTACCESS,">".$rootdir."/bad_ip.txt") ¦¦ die $!;
print HTACCESS "\^".$visitor_ip."\$\n\# $date\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>Error</title>\n<META NAME=\"robots\" CONTENT=\"NOINDEX,NOFOLLOW\">\n";
print "</head>\n";
print "<body>\n";
print "<p><b>A fatal error has occured:</b></p>\n";
print "<p><b>Invalid Site HTML method...</b></p>\n";
print "<p><b>Please enable debugging in setup for more details.</b></p>\n";
print "<A HREF=\"http://www.imdb.com/harvest_me/\"> </A>\n";
print "</body>\n";
print "</html>\n";
exit;

}

########################## END OF SCRIPT

OK, so take and pop this little puppie into the same directory you want protected, chmod 755. I use a file I call "bad_ip.txt" to hold my bad IP's, but you can change to anything (including .htaccess, but make sure you escape the "."!) This will write to the TOP of any file you have set up, so, the older stuff goes down two linbes every time this gets written to.

If you edit bad_ip.txt (or .htaccess) make SURE to upload to your server ASCII, or it wiull not work.

I think that is it... comments welcome!

dave


Thread source:: http://www.webmasterworld.com/search_engine_spiders/1515.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com