From 36bf7d3c29dc07d27866395b3e2c2f6582a09209 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Thu, 1 Aug 2024 14:13:48 -0700 Subject: [PATCH] Add simple client --- client.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 client.py diff --git a/client.py b/client.py new file mode 100755 index 0000000..9adbabe --- /dev/null +++ b/client.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +import argparse +import logging +import socket +import sys + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("host", help="The IPv6 address of the host to connect to.") + parser.add_argument("--port", "-p", default=50007, help="The port to connect to.") + args = parser.parse_args() + + s = None + for res in socket.getaddrinfo(args.host, args.port, socket.AF_UNSPEC, socket.SOCK_STREAM): + af, socktype, proto, canonname, sa = res + try: + s = socket.socket(af, socktype, proto) + except OSError as msg: + s = None + continue + try: + s.connect(sa) + except OSError as msg: + s.close() + s = None + continue + break + if s is None: + print('could not open socket') + sys.exit(1) + with s: + s.sendall(b'Hello, world') + data = s.recv(1024) + print('Received', repr(data)) + + if __name__ == "__main__": + main() + +if __name__ == "__main__": + main()