diff options
Diffstat (limited to 'sockets/chat_client.py')
| -rw-r--r-- | sockets/chat_client.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/sockets/chat_client.py b/sockets/chat_client.py new file mode 100644 index 0000000..affc1d3 --- /dev/null +++ b/sockets/chat_client.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import sys,socket,os + +def chat_client(host,port): + whoami = os.getenv("USER") + try: + s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + s.connect((host,port)) + while True: + message = input("moi > ") + message = whoami+" > "+message # à commenter pour le bindshell + s.sendall(message.encode()) + data = s.recv(1024) + print(data.decode().strip()) + except KeyboardInterrupt: + s.close() + finally: + print("bye") + +if __name__ == "__main__": + try: + chat_client(sys.argv[1],int(sys.argv[2])) + except IndexError: + print(f"{sys.argv[0]} demande un hôte où se connecter et un numéro de port") + |
