summaryrefslogtreecommitdiff
path: root/sockets/chat_client.py
diff options
context:
space:
mode:
authorjerome <jerome@xlinfo.fr>2025-10-12 17:41:43 +0200
committerjerome <jerome@xlinfo.fr>2025-10-12 17:41:43 +0200
commitec8893a097a6c0fffebd7db9e4a5568a3bf4df47 (patch)
treeffebe60c3aa98df05d14aec8cea937430272c1ec /sockets/chat_client.py
parentba41fa46e69dbb264dfbed1b9fca5daab44a07c7 (diff)
downloadpython-ec8893a097a6c0fffebd7db9e4a5568a3bf4df47.tar.gz
python-ec8893a097a6c0fffebd7db9e4a5568a3bf4df47.zip
organisation
Diffstat (limited to 'sockets/chat_client.py')
-rw-r--r--sockets/chat_client.py26
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")
+