Python写的UDP Server端口转发,可用于协议分析

Python写的UDP Server端口转发,可用于协议分析

 

#udp server
import socket

host = '127.0.0.1'
port = 6001 #Real Server Port
port2 = 8999 #Map to Serer Port

def ProcData(data):
    return data
    #add more code....

server = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
server.bind(('127.0.0.1',port))
print "127.0.0.1 Sever start at %s\n" %port

client = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
print host +" Client connect to %s\n" %port2

while 1:
    msg,(addr,port) = server.recvfrom(2048,)
    print "Serer got data %s from "%repr(msg),addr,port

    client.sendto(msg, (host, port2) )
    print "Client send data %s to "%repr(msg),host,port2
    buf=client.recv(1024)

    print "Client recv data %s from "%repr(buf),host,port2

    server.sendto(buf,(addr,port))
    print "Serer send data %s to "%repr(buf),addr,port


 

你可能感兴趣的:(开发语言类)