Skip to content

Instantly share code, notes, and snippets.

@taida957789

taida957789/s.py

Created May 6, 2015
Embed
What would you like to do?
udp nat
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