Skip to content

Instantly share code, notes, and snippets.

@anri-c
Created June 1, 2012 03:59
Show Gist options
  • Save anri-c/2848623 to your computer and use it in GitHub Desktop.
Save anri-c/2848623 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