저는 파이썬에서 연결하고 대답 할 때 서버로부터 수학 문제를 가져와야하는 TCP 클라이언트를 작성하고 있습니다. 내가 netcat을 사용하여 서버에 연결 와이어 샤크에 이것을보고 : 내 코드로했을 때 나는 서버가 질문을 전송 한 후 유일한 차이점은 내 코드 아무튼되는이 Python TCPclient 인정 안 함
그것으로 ACK를 보내지 마라.
서버가 메시지에 이러한 문제를 캡슐화하는 데 사용하는 프로토콜이 무엇이든import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = 'x.x.x.x'
port = 1337
s.connect((host, port))
while 1:
data = s.recv(1024)
print(data)
splited_data = data.splitlines()
exercise = splited_data[-1].decode("utf-8")
print(exercise)
exercise = splited_data[-1].split()
num1 = int(exercise[0])
arithmetic = exercise[1].decode("utf-8")
num2 = int(exercise[2])
if arithmetic == '+':
answer = num1 + num2
elif arithmetic == '-':
answer = num1 - num2
elif arithmetic == '*':
answer = num1 * num2
elif arithmetic == '/':
answer = num1/num2
elif arithmetic == '%':
answer = num1 % num2
else:
print(arithmetic)
print(answer)
print(str(answer).encode('utf-8'))
s.send(str(answer).encode('utf-8'))
하지만 netcat을 사용하여 메시지를 보내고받을 수있는 방법은 무엇입니까? AFAIK ACK는 socket.recv를 할 때 자동으로 전송됩니다. –
@ YonatanKreiner 서버가 사용하는 프로토콜을 모르면 어떻게 실패하는지 정확하게 설명 할 수 없습니다. 그러나 전혀 프로토콜을 구현하지 않으므로 확실히 실패 할 것입니다. (당신이 내 대답을 향상시킬 수 있도록 귀하의 질문에 사용하는 프로토콜의 세부 정보를 추가 할 수 있습니까?) –
그 CTF 난 그냥 TCP를 통해 데이터를 보내고받을 필요가 Netcat 함께 할 –