-
-
Save taida957789/6614c490248599e7972d to your computer and use it in GitHub Desktop.
udp nat
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
import socket | |
UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) | |
listen_addr = ("", 3386) | |
UDPSock.bind(listen_addr) | |
ips = [] | |
while True: | |
data,addr = UDPSock.recvfrom(1024) | |
print addr , 'is connected.' | |
ips.append(str(addr[0]) + ':' + str(addr[1])) | |
if(len(ips) == 2): | |
dest = '' | |
for ip in ips: | |
for i in ips: | |
if ip != i: | |
dest = i | |
UDPSock.sendto(dest, (ip.split(':')[0],int(ip.split(':')[1]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment