import socket ms=socket.socket(socket.AF_INET,socket.SOCK_STREAM) host="192.168.0.159" port=80 ms.bind((host, port)) ms.listen(5) while True: conn,addr=ms.accept() data=conn.recv(1000) if not data: break print (data) print ("Got a request!\n") conn.close() ms.close()
You cannot bind to ports below 1024 without the CAP_NET_BIND_SERVICE capability. The root user has it.
Or, you can assign it to an executable with
$ sudo setcap 'cap_net_bind_service=+ep' /path/to/program
But, caveat, the latter does not work for scripts. You had to add the capability to the interpreter itself, which is a huge security hole. Don't do that.