Skip to content
Advertisement

I can’t get a response from the server via socket python

  import socket

  with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as socket_server:

    socket_server.connect(("77.222.42.207", 1337))
    socket_server.send("get_flag".encode())

    server_unswer = (socket_server.recv(1024)).decode()
    print(server_unswer)

    while (messsage := input("Я: ")) != "exit":
      socket_server.send(messsage.encode())
      messsage = socket_server.recv(1024)
      messsage = messsage.decode()
      print(messsage)

I’m trying to send a string to the server, but I can’t send the data and get a response, what’s the problem, please help.

When I connect to the server via netcat, everything is fine.

Advertisement

Answer

import socket

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as socket_server:

  socket_server.connect(("77.222.42.207", 1337))

  server_unswer = (socket_server.recv(1024)).decode()
  print(server_unswer)

  socket_server.send("get_flagn".encode())

  server_unswer = (socket_server.recv(1024)).decode()
  print(server_unswer)

I was finally able to get a response from the server, it was because NetCat automatically adds n when sending text and the command on the server worked, but I did not add this character when sending text 🤦

I had to figure out how to use Wireshark to figure it out)

Advertisement