15 lines
592 B
Python
15 lines
592 B
Python
import socket
|
|
import struct
|
|
|
|
|
|
if __name__ == '__main__':
|
|
in_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
in_socket.bind(('', 9999))
|
|
out_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
out_socket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack('b', 1))
|
|
print("ready: listening on UDP :9999, forwarding to 224.0.2.0:10000", flush=True)
|
|
while True:
|
|
data, addr = in_socket.recvfrom(1024)
|
|
out_socket.sendto(data, ('224.0.2.0', 10000))
|
|
print(f'forwarded {data!r} from {addr} to 224.0.2.0:10000', flush=True)
|