All pastes #519662 Raw Edit

Mine

public python v1 · immutable
#519662 ·published 2007-05-29 18:48 UTC
rendered paste body
#!/usr/bin/env pythonimport osimport time,sysdef getIP(theString):        bla = theString.replace("(?@","^")        bla2 = bla.replace(")","^")        finalstring = bla2.split("^")        return finalstring[1]def blockIP(ipAddr):        os.system("route add -host " + str(ipAddr) + " reject")def logIT(ipAddr):        flog = open('/var/log/ftp-firewall.log','a')        flog.write('Blocked : ' + str(ipAddr) + '[' + time.ctime() + ']' + '\n' )        flog.close()f=open("/var/log/messages.log")readBuffer = ''while True:        readBuffer += f.read()        lastNewline = readBuffer.rfind('\n')        outputbuffer = readBuffer[:lastNewline].split('\n')        for line in outputbuffer:                if len(line)>0:                        if line.find("Authentication failed") !=-1:                                OffenderIP = getIP(line)                                blockIP(OffenderIP)                                logIT(OffenderIP)                readBuffer = readBuffer[lastNewline+1:]                time.sleep(1)