Created
October 22, 2021 22:40
-
-
Save ghost-ng/37d5d4c23bedaf9ca02c99c7b78ad094 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
from socket import * | |
import sys | |
bufsize = 1024 # Modify to suit your needs | |
try: | |
listenHost = sys.argv[1].split(":")[0] | |
listenPort = int(sys.argv[1].split(":")[1]) | |
connectHost = sys.argv[2].split(":")[0] | |
connectPort = int(sys.argv[2].split(":")[1]) | |
except: | |
print "USAGE: %s [listenHost]:[listenPort] [connectHost]:[connectPort]" % sys.argv[0] | |
sys.exit() | |
def forward(data, port): | |
print "Forwarding: '%s' from port %s" % (data, port) | |
sock = socket(AF_INET, SOCK_DGRAM) | |
sock.bind(("localhost", port)) # Bind to the port data came in on | |
sock.sendto(data, (connectHost, connectPort)) | |
def listen(host, port): | |
listenSocket = socket(AF_INET, SOCK_DGRAM) | |
listenSocket.bind((host, port)) | |
while True: | |
data, addr = listenSocket.recvfrom(bufsize) | |
forward(data, addr[1]) # data and port | |
listen(listenHost, listenPort) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment