我有一个获取命令并在 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()
我尝试对它进行同步洪水攻击,但它崩溃了。我想保护它免受同步洪水攻击,我该怎么做?我是套接字编程的新手,所以我很乐意得到一些建议^_^