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

来源:互联网 发布:无敌淘宝网下载 编辑:程序博客网 时间:2024/06/07 11:10

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

 

#tcp serverimport sockethost = '127.0.0.1'          #Local Server IPhost2 = '127.0.0.1'   #Real Server IPport = 6001 #Local Server Portport2 = 7001 #Real Server Portdef ProcData(data):    return data    #add more code....print "Map Server start from " + 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',addrwhile 1:    msg = ss.recv(20480)    print "Get:"+repr(msg)+"\r\n"    client.send(msg)    #print "Client send data %s to "%repr(msg)    buf=client.recv(20480)    #print "Client recv data %s from "%repr(buf)    ss.send(buf)    print "Send:"+repr(buf)+"\r\n"


 

原创粉丝点击