I am trying to create a program that will open a port on a local computer and allow others to connect to it via netcat. My current code.
s = socket.socket() host = '127.0.0.1' port = 12345 s.bind((host, port)) s.listen(5) while True: c, addr = s.accept() print('Got connection from', addr) c.send('Thank you for connecting') c.close()
I am new to Python and sockets. But when I run this code, it will allow me to send a netcat connection using the command:
nc 127.0.0.1 12345
But then in my Python script, I get an error for c.send:
TypeError: a bytes-like object is required, not 'str'
I am just trying to open a port, allow netcat to connect and have a full shell on this machine.
source share