I have a piece of python code as follow
s = socket.socket() s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((IP, PORT)) s.listen(256) while True: revdata = "" try: c, addr = s.accept() t = threading.Thread(target=handletcp, args=(c,addr)) t.start() except socket.error as exc: log("Error: " + str(exc)) s.close()
Currently, my server, which handles 64 IPs, usually gets SYN flood attack. The python service has maximum ~200 TCP connections normally. I want to detect SYN flood attack and suspend the service within python code. Any idea of how to do that efficiently?
Thanks in advance!