Custom Search

Sunday, October 18, 2009

Simple DDoS Mitigation

#!/usr/bin/env python
#By Fallen
import os, time
CONLIMIT = 20
SLEEP = 12
Round = 0
Banned = 0
while True:
Round += 1
for Line in os.popen("netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n", "r").read().split("\n"):
List = Line.split(" ")
try:
if int(List[-2]) > CONLIMIT:
os.system( "route add %s gw 127.0.0.1 lo" % ( List[ -1 ] ) )
print "Banning %s...." % ( List[ -1 ] )
Banned += 1
except Exception:
pass
print "Round: %s Bans: %s" % ( str(Round), str(Banned) )
time.sleep(SLEEP)

1 comment:

  1. Very nice. I wouold suggest adding a "follow me" gadget so people can follow your blog. thanks :)

    ReplyDelete