Example #1
0
    def set_proxy(self):
        """Setup a socks connection for the socks module bound to this instance.

        Args:
            proxy: Namedtuple, Proxy to use for this thread.
        """

        def create_connection(address, timeout=None, source_address=None):
            sock = socks.socksocket()
            sock.connect(address)
            return sock

        pmapping = {
            'socks4': 1,
            'socks5': 2,
            'http': 3
        }
        if self.proxy:
            self.request_proxies = {
                'http': 'http://{}:{}'.format(self.proxy.host, self.proxy.port),
                'https': 'https://{}:{}'.format(self.proxy.host, self.proxy.port)
            }
        # Patch the socket module
        # rdns is by default on true. Never use rnds=False with TOR, otherwise you are screwed!
        socks.setdefaultproxy(pmapping.get(self.proxy.proto), self.proxy.host, int(self.proxy.port), rdns=True)
        socks.wrap_module(socket)
        socket.create_connection = create_connection
Example #2
0
    def _set_proxy(self, proxy):
        def create_connection(address, timeout=None, source_address=None):
            sock = socks.socksocket()
            sock.connect(address)
            return sock

        pmapping = {'socks4': 1, 'socks5': 2, 'http': 3}
        # Patch the socket module  # rdns is by default on true. Never use rnds=False with TOR, otherwise you are screwed!
        socks.setdefaultproxy(pmapping.get(proxy.proto),
                              proxy.host,
                              int(proxy.port),
                              rdns=True)
        socks.wrap_module(socket)
        socket.create_connection = create_connection
Example #3
0
    def _set_proxy(self, proxy):
        def create_connection(address, timeout=None, source_address=None):
            sock = socks.socksocket()
            sock.connect(address)
            return sock

        pmapping = {
            'socks4': 1,
            'socks5': 2,
            'http': 3
        }
        # Patch the socket module  # rdns is by default on true. Never use rnds=False with TOR, otherwise you are screwed!
        socks.setdefaultproxy(pmapping.get(proxy.proto), proxy.host, int(proxy.port), rdns=True)
        socks.wrap_module(socket)
        socket.create_connection = create_connection