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(' ') 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
- 11.19.12 / 11pm
- Engineering notes