예제 #1
0
 def __init__( self, port, verify_163):
     Thread.__init__( self )
     self.proxy_retriever = ProxyRetriever(verify_163)
     newhost, newport = self.proxy_retriever.getAProxy()
     log( 'Redirecting: localhost:%s -> %s:%s' % ( port, newhost, newport ))
     self.newhost = newhost
     self.newport = newport
     self.sock = socket( AF_INET, SOCK_STREAM )
     self.sock.bind(( '', port ))
     self.sock.listen(5)
     self.running = True
예제 #2
0
class Pinhole( Thread ):
    def __init__( self, port, verify_163):
        Thread.__init__( self )
        self.proxy_retriever = ProxyRetriever(verify_163)
        newhost, newport = self.proxy_retriever.getAProxy()
        log( 'Redirecting: localhost:%s -> %s:%s' % ( port, newhost, newport ))
        self.newhost = newhost
        self.newport = newport
        self.sock = socket( AF_INET, SOCK_STREAM )
        self.sock.bind(( '', port ))
        self.sock.listen(5)
        self.running = True

    def run( self ):
        while self.running:
            newsock, address = self.sock.accept()
            log( 'Creating new session for %s %s ' % address )
            #fwd = socket( AF_INET, SOCK_STREAM )
            while 1:
                try:
                    fwd = create_connection(( self.newhost, self.newport ), 1)
                except timeout:
                    newhost, newport = self.proxy_retriever.getAProxy()
                    self.newhost = newhost
                    self.newport = newport
                    continue
                except Exception as e:
                    print e
                    self.sock.close()
                    self.running = False
                break

            if not self.running:
                break

            PipeThread( newsock, fwd ).start()
            PipeThread( fwd, newsock ).start()