Python saves my day

I have tried to configure my spelling proxy so I have one internal and one external. This isn't that easy thought, since the requests are Ajax based.

On the end of the day I got a brilliant idea, leave it open and have a Python script that can scan Apaches log to see if a client has made too many requests. This is probably the best way to protect against someone that misuse the proxy. One can use Apache's ProxyBlock to block an user.

Here is the log analyzer script if anyone should find it useful:

ip_count = {}
for line in open("access.log").readlines():
  if line.find("noxspell") != -1:
    offset = line.find("-")
    ip = line[0:offset-1]
    ip_count[ip] = ip_count.get(ip, 0) + 1
ip_keys = ip_count.keys()
ip_keys.sort()

for ip_k in ip_keys:
  if ip_count[ip_k] > 250:
    print "%s had %s req" % (ip_k, ip_count[ip_k])
Code · Python 18. Apr 2006
© Amir Salihefendic. Powered by Skeletonz.