• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

python编写的超简单端口转发程序

python 水墨上仙 1656次浏览

python编写的超简单端口转发程序

代码非常简单,实现了简单的端口数据转发功能,用于真实环境还需要再修改一下。

转自:http://blog.csdn.net/qffhq

#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 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',addr  
  
while 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"  


喜欢 (0)
加载中……