标签:python
def handler(chan,host,port): sock = socket.socket() try: sock.connect((host,port)) except Exception as e: verbose(‘Forwarding request to %s:%d failed: %r ‘ % (host,port,e)) return verbose(‘Connected! Tunnel open %r -> %r -> %r‘ % (chan.orgin_addr,chan.getpeername(),(host,port))) while True: r,w,x = select.select([sock,chan],[],[]) if sock in r: data = sock.recv(1024) if len(data) == 0: break chan.send(data) if chan in r: data = chan.recv(1024) if len(data)==0: break sock.send(data) chan.close() sock.close() verbose("Tunnel closed from %r " % (chan.orgin_addr,))
本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1770182
标签:python
原文地址:http://jingshanls.blog.51cto.com/3357095/1770182