Python-written TCP server port forwarding, which can be used for protocol analysis
#tcp Server Import Socket host = ' 127.0.0.1 ' #Local server IP host2 = ' 127.0.0.1 ' #Real server IP port = 6001 #Local Server Port Port2 = 7001 #Real server port def procdata (data): Return data #add more code ... print "Map Server Start "+ Host +": "+ str (port) +" to "+ Host2 +": "+ str (PORT2) +" \ r \ n "Server = Socket.socket socket. Af_inet,socket. Sock_stream) Server.bind ((' 127.0.0.1 ', port) print "127.0.0.1 server start at" + STR (port) + "\ r \ n" client = Socket.socket (socket.af_inet, Socket.) Sock_stream) Client.connect ((HOST2,PORT2)) Print Host + "Client connect to" + Host2 + ":" +str (port2) + "\ n" server.listen (5) ss, addr = server.accept () print ' Got connected from ', addr while 1:msg = Ss.recv (20480) print "Get:" +repr (ms g) + "\ r \ n" client.send (msg) #print "Client send data%s to"%REPR (msg) BUF=CLIENT.RECV (20480) #print "Cli
ENT recv data%s from "%repr (BUF) ss.send (buf) print" Send: "+repr (BUF) +" \ r \ n "