Created
October 23, 2017 17:30
-
-
Save g-andrade/e0ee75f12739499396489c75148f0ddb to your computer and use it in GitHub Desktop.
TCP client-to-client tunnel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import select | |
import socket | |
import sys | |
tcp_ipA = sys.argv[1] | |
tcp_portA = int(sys.argv[2]) | |
tcp_ipB = sys.argv[3] | |
tcp_portB = int(sys.argv[4]) | |
connA = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
connB = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
connA.connect((tcp_ipA, tcp_portA)) | |
connB.connect((tcp_ipB, tcp_portB)) | |
active = True | |
while active: | |
inputs = [connA, connB] | |
outputs = [] | |
readable, writable, exceptional = select.select(inputs, outputs, inputs, 1.0) | |
for conn,rconn in [(connA,connB), (connB,connA)]: | |
if conn in readable: | |
data = conn.recv(1024) | |
if len(data) < 1: | |
print '%s closed connection to %s' % (conn.getpeername(), rconn.getpeername()) | |
rconn.close() | |
active = False | |
break | |
rconn.send(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment