Netcat implementation in Python

Does it work if you just use nc? I think you should try something a little simpler: import socket def netcat(hostname, port, content): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((hostname, port)) s.sendall(content) s.shutdown(socket.SHUT_WR) while 1: data = s.recv(1024) if len(data) == 0: break print(“Received:”, repr(data)) print(“Connection closed.”) s.close() I added the shutdown call because maybe your device … Read more

Minimal web server using netcat

Try this: while true ; do nc -l -p 1500 -c ‘echo -e “HTTP/1.1 200 OK\n\n $(date)”‘; done The -cmakes netcat execute the given command in a shell, so you can use echo. If you don’t need echo, use -e. For further information on this, try man nc. Note, that when using echo there is … Read more