THIS DOES NOT WORK WITH APACHE SINCE IT DOES NOT USE /etc/hosts.deny - See this post instead
Use the following Python script to maintain a file in the hosts.deny syntax so that your Debian/Ubuntu box (or other Linux server) is kept undisturbed by forum spammers -- COMPLETELY undisturbed, as the spammer is disallowed all access to the system.
1. Copy the script to a file on your server, eg. /usr/sbin/stopforumspam.py
2. Make the file executable, eg. chmod +x /usr/sbin/stopforumspam.py
3. Add it to your crontab for automatic execution each night, eg. crontab -e and then insert the line 0 0 * * * /usr/sbin/stopforumspam.py
4. Add the path to the file containing the ip list to /etc/hosts.deny by inserting this line: ALL: /etc/hosts.deny.stopforumspam
The script itself is here, modify it as you need.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #!/usr/bin/python import re import urllib import zipfile DOWNLOAD_ZIP = "http://www.stopforumspam.com/downloads/listed_ip_7.zip" ZIP_FILENAME = "listed_ip_7.txt" HOSTS_DENY = "hosts.deny.stopforumspam" # For security purposes we test that each line is actually an IP address IP_MATCH = re.compile(r"\d+\.\d+\.\d+\.\d+") filename, headers = urllib.urlretrieve(DOWNLOAD_ZIP) z = zipfile.ZipFile(filename) ips = z.read(ZIP_FILENAME) deny_file = file(HOSTS_DENY, "w") for ip in ips.split("\n"): if IP_MATCH.match(ip): deny_file.write("%s\n" % ip) deny_file.close() |