Make pipe/tcp tools accept IPs

This commit is contained in:
Fierelier 2021-04-21 14:03:25 +02:00
parent 48375013b1
commit bf8505554f
2 changed files with 27 additions and 7 deletions

View File

@ -24,12 +24,6 @@ import queue
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) 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 connection = False
connectionLock = threading.Lock() connectionLock = threading.Lock()
@ -50,6 +44,22 @@ class pipeThread(threading.Thread):
connection = False connection = False
print(e) 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 = pipeThread()
pThread.start() pThread.start()

View File

@ -22,10 +22,20 @@ import socket
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) 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) serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
eprint("Opening socket...") eprint("Opening socket...")
serverSocket.bind(serverAddr) serverSocket.bind(serverAddr)
eprint("Serving on " +addressTupleToString(serverAddr)+ "!")
serverSocket.listen(1) serverSocket.listen(1)
while True: while True: