Banning spammers on a low traffic site
I’ve a low/zero traffic site that attracts more bots than human visitors. Here’s a simple Python script that looks through the logs and bans visitors who try to spam the comments page.
import os, time
banned_ips = []
while True:
fd = os.popen("tail access_log | grep commentStart")
txt = fd.read()
fd.close()
for line in txt.split('\n'):
ip = line.split(' ')[0]
if ip and not ip in banned_ips:
banned_ips.append(ip)
print "Banning", ip
os.system('sudo iptables -A INPUT -s %s/24 -j DROP' % ip)
time.sleep(1)
In addition, project honeypot is interesting as well.
About this entry
You’re currently reading “ Banning spammers on a low traffic site ,” an entry on Chui's Counterpoint
- Published:
- 11.19.12 / 11pm
- Category:
- Engineering notes
Comments are closed
Comments are currently closed on this entry.