From bf8505554f36782b0d6f753a0237d5286e4e6a63 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 21 Apr 2021 14:03:25 +0200 Subject: [PATCH] Make pipe/tcp tools accept IPs --- fstream-util-pipe_to_tcp.py | 22 ++++++++++++++++------ fstream-util-tcp_to_pipe.py | 12 +++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/fstream-util-pipe_to_tcp.py b/fstream-util-pipe_to_tcp.py index f10ca22..e14c034 100644 --- a/fstream-util-pipe_to_tcp.py +++ b/fstream-util-pipe_to_tcp.py @@ -24,12 +24,6 @@ import queue def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) -serverAddr = ("127.0.0.1",61921) -serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -eprint("Opening socket...") -serverSocket.bind(serverAddr) -serverSocket.listen(1) - connection = False connectionLock = threading.Lock() @@ -50,6 +44,22 @@ class pipeThread(threading.Thread): connection = False print(e) +def stringToAddressTuple(addr): + rtn = addr.rsplit(":",1) + rtn[1] = int(rtn[1]) + rtn = tuple(rtn) + return rtn + +def addressTupleToString(addr): + return ":".join(map(str,list(addr))) + +serverAddr = stringToAddressTuple(sys.argv[1]) +serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +eprint("Opening socket...") +serverSocket.bind(serverAddr) +eprint("Serving on " +addressTupleToString(serverAddr)+ "!") +serverSocket.listen(1) + pThread = pipeThread() pThread.start() diff --git a/fstream-util-tcp_to_pipe.py b/fstream-util-tcp_to_pipe.py index 6f0073e..9276cf6 100644 --- a/fstream-util-tcp_to_pipe.py +++ b/fstream-util-tcp_to_pipe.py @@ -22,10 +22,20 @@ import socket def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) -serverAddr = ("127.0.0.1",61921) +def stringToAddressTuple(addr): + rtn = addr.rsplit(":",1) + rtn[1] = int(rtn[1]) + rtn = tuple(rtn) + return rtn + +def addressTupleToString(addr): + return ":".join(map(str,list(addr))) + +serverAddr = stringToAddressTuple(sys.argv[1]) serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) eprint("Opening socket...") serverSocket.bind(serverAddr) +eprint("Serving on " +addressTupleToString(serverAddr)+ "!") serverSocket.listen(1) while True: