Skip to content

Instantly share code, notes, and snippets.

@empjustine
Forked from anri-c/UDPDuplicator.py
Created August 10, 2021 02:38
Show Gist options
  • Save empjustine/98b5e1506f2926b5fefe727c2d67d423 to your computer and use it in GitHub Desktop.
Save empjustine/98b5e1506f2926b5fefe727c2d67d423 to your computer and use it in GitHub Desktop.
Duplicate UDP Packets
# -*- coding: utf-8 -*-
import SocketServer as Ss
import socket
import threading
TARGETS = {'target_host1', 'target_host2'}
PORT = 8989
class DuplicateUDP(Ss.BaseRequestHandler):
def handle(self):
data = self.request[0]
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
for tgt in TARGETS:
sock.sendto(data, (tgt, PORT))
class ThreadedUDPServer(Ss.ThreadingMixIn, Ss.UDPServer):
pass
if __name__ == '__main__':
HOST = '0.0.0.0'
udpsv = ThreadedUDPServer((HOST, PORT), DuplicateUDP)
udp_thread = threading.Thread(target=udpsv.serve_forever)
udp_thread.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment