示例#1
0
 def smart_socks_tcp( self, forwardurl, req):
     remoteconn = socket.create_connection((forwardurl.hostname, forwardurl.port), self.timeout)
     remoteconn.settimeout(self.timeout)
     handler = SocksForwardSession(self.socksconn, remoteconn)
     self.handler = handler
     
     # handshake, send request, then start to pipe
     if self.forward_handshake(handler.remoteconn):
         handler.proc_tcp_request(req)
         handler.relay_tcp()
示例#2
0
 def forward_socks5_tcp(self, url, req):
     remoteconn = socket.create_connection((url.hostname, url.port), self.timeout)
     remoteconn.settimeout(self.timeout)
     handler = SocksForwardSession(self.socksconn, remoteconn)
     self.handler = handler
     # handshake, send request, then start to pipe
     if self.forward_socks5_handshake(handler.remoteconn):
         handler.proc_tcp_request(req)
         handler.relay_tcp()
     return True
示例#3
0
 def smart_socks_udp(self, forwardurl, local_handler, firstdata, firstaddr):
     remoteconn = socket.create_connection((forwardurl.hostname, forwardurl.port), self.timeout)
     remoteconn.settimeout(self.timeout)
     handler = SocksForwardSession(self.socksconn, remoteconn)
     
     # copy already-exist states from previous handler
     handler.client_associate = local_handler.client_associate
     handler.last_clientaddr = local_handler.last_clientaddr
     handler.client2local_udpsock = local_handler.client2local_udpsock
     handler.track_sock(handler.client2local_udpsock)
     self.handler = handler
     
     # handshake, then request-reply, then send first packet, finally start to pipe
     if self.forward_handshake(handler.remoteconn):
         handler.local2remote_udpsock = bind_local_udp(handler.remoteconn)
         handler.track_sock(handler.local2remote_udpsock)
         send_request(handler.remoteconn, UDP_ASSOCIATE, *sock_addr_info(handler.local2remote_udpsock))
         reply = read_reply(handler.remoteconn)
         if reply.rep != SUCCEEDED:
             return           
         handler.remote_associate = (reply.bndaddr, reply.bndport)
         handler.last_clientaddr = firstaddr
         handler.local2remote_udpsock.sendto(firstdata, handler.remote_associate)
         handler.relay_udp() 
示例#4
0
    def smart_socks_udp(self, forwardurl, local_handler, firstdata, firstaddr):
        remoteconn = socket.create_connection(
            (forwardurl.hostname, forwardurl.port), self.timeout)
        remoteconn.settimeout(self.timeout)
        handler = SocksForwardSession(self.socksconn, remoteconn)

        # copy already-exist states from previous handler
        handler.client_associate = local_handler.client_associate
        handler.last_clientaddr = local_handler.last_clientaddr
        handler.client2local_udpsock = local_handler.client2local_udpsock
        handler.track_sock(handler.client2local_udpsock)
        self.handler = handler

        # handshake, then request-reply, then send first packet, finally start to pipe
        if self.forward_handshake(handler.remoteconn):
            handler.local2remote_udpsock = bind_local_udp(handler.remoteconn)
            handler.track_sock(handler.local2remote_udpsock)
            send_request(handler.remoteconn, UDP_ASSOCIATE,
                         *sock_addr_info(handler.local2remote_udpsock))
            reply = read_reply(handler.remoteconn)
            if reply.rep != SUCCEEDED:
                return
            handler.remote_associate = (reply.bndaddr, reply.bndport)
            handler.last_clientaddr = firstaddr
            handler.local2remote_udpsock.sendto(firstdata,
                                                handler.remote_associate)
            handler.relay_udp()