• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python写的Socks5协议代理服务器

python 搞代码 4年前 (2022-01-09) 14次浏览 已收录 0个评论

直接上代码:

#!/usr/bin/python # Filename s5.py # Python Dynamic Socks5 Proxy # Usage: python s5.py 1080 # Background Run: nohup python s5.py 1080 & import socket, sys, select, SocketServer, struct, time class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): passclass Socks5Server(SocketServer.StreamRequestHandler):   def handle_tcp(self, sock, remote):     fdset = [sock, remote]     while True:       r, w, e = select.select(fdset, [], [])       if sock in r:         if remote.send(sock.recv(4096)) <= 0: break       if remote in r:         if sock.send(remote.recv(4096)) H', self.rfile.read(2))       reply = "\x05\x00\x00\x01"       try:         if mode == 1: # 1. Tcp connect           remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)           remote.connect((addr, port[0]))           pass # print 'To', addr, port[0] nothing do to.         else:           reply = "\x05\x07\x00\x01" # Command not supported         local = remote.getsockname()         reply += socket.inet_aton(local[0]) + struct.pack(">H", local[1])      except socket.error:         # Connection refused         reply = '\x05\x05\x00\x01\x00\x00\x00\x00\x00\x00'       sock.send(reply)       # 3. Transfering       if reply[1] == '\x00': # Success         if mode == 1:  # 1. Tcp connect           self.handle_tcp(sock, remote)     except socket.error:       pass #print 'error' nothing to do .<div style="color:transparent">本文来源gaodai.ma#com搞#代!码(网</div>     except IndexError:       pass def main():   filename = sys.argv[0];   if len(sys.argv)<2:     print 'usage: ' + filename + ' port'     sys.exit()   socks_port = int(sys.argv[1]);     server = ThreadingTCPServer(('', socks_port), Socks5Server)   print 'bind port: %d' % socks_port + ' ok!'   server.serve_forever() if __name__ == '__main__':   main()

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python写的Socks5协议代理服务器
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址