I have an example of a server that gets commands and returns answers in python:
import socket
import time
import random
CommandDict = {"TIME" : time.strftime("%d-%m-%Y"),"NAME": "Ori","RANDOM": str(random.randint(0,10))}
server_socket = socket.socket()
server_socket.bind(('127.0.0.1',8820))
server_socket.listen(5)
while True:
print "Waiting for commands"
(client_socket, client_address) = server_socket.accept()
client_data = client_socket.recv(1024)
print "GOT COMMAND FROM " + client_address[0] + " : " + client_data
try:
client_socket.send(CommandDict[client_data])
except Exception:
client_socket.send("ERROR!")
client_socket.close()
server_socket.close()
i tried a syn flood attack on it and it crashed. i want to defend it from syn flood attacks, how could i do it? i'm new to socket programming so i would be happy to get some advices ^_^