Created
January 15, 2014 19:51
-
-
Save olavmrk/8443205 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import socket | |
import struct | |
import sys | |
src_ip = sys.argv[1] | |
src_port = int(sys.argv[2]) | |
dst_addr = sys.argv[3] | |
dst_port = int(sys.argv[4]) | |
src = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
src.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
src.bind(('', src_port)) | |
mreq = struct.pack('4sI', socket.inet_aton(src_ip), socket.INADDR_ANY) | |
src.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) | |
dst = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
dst.connect( (dst_addr, dst_port) ) | |
while True: | |
data = src.recv(65535) | |
dst.send(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment