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.