Python pycurl.PROXYTYPE Examples

The following are 6 code examples of pycurl.PROXYTYPE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pycurl , or try the search function .
Example #1
Source File: custom_path_selection.py    From stem with GNU Lesser General Public License v3.0 6 votes vote down vote up
def query(url):
  """
  Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
  """

  output = StringIO.StringIO()

  query = pycurl.Curl()
  query.setopt(pycurl.URL, url)
  query.setopt(pycurl.PROXY, 'localhost')
  query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
  query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
  query.setopt(pycurl.CONNECTTIMEOUT, CONNECTION_TIMEOUT)
  query.setopt(pycurl.WRITEFUNCTION, output.write)

  try:
    query.perform()
    return output.getvalue()
  except pycurl.error as exc:
    raise ValueError("Unable to reach %s (%s)" % (url, exc)) 
Example #2
Source File: client_usage_using_pycurl.py    From stem with GNU Lesser General Public License v3.0 6 votes vote down vote up
def query(url):
  """
  Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
  """

  output = io.BytesIO()

  query = pycurl.Curl()
  query.setopt(pycurl.URL, url)
  query.setopt(pycurl.PROXY, 'localhost')
  query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
  query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
  query.setopt(pycurl.WRITEFUNCTION, output.write)

  try:
    query.perform()
    return output.getvalue()
  except pycurl.error as exc:
    return "Unable to reach %s (%s)" % (url, exc)


# Start an instance of Tor configured to only exit through Russia. This prints
# Tor's bootstrap information as it starts. Note that this likely will not
# work if you have another Tor instance running. 
Example #3
Source File: torutil.py    From onion-expose with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _check_status(self):
        """
        For internal use only. Only members of :class:`Tunnel`
        """
        try:
            output = io.BytesIO()

            query = pycurl.Curl()
            query.setopt(pycurl.URL, "%s:%s" % (self.addr, self.status_server.port))
            query.setopt(pycurl.PROXY, "127.0.0.1")
            query.setopt(pycurl.PROXYPORT, config.tor_proxy_port)
            query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
            query.setopt(pycurl.WRITEFUNCTION, output.write)
            query.perform()

            return "ONIONGROK_CLIENT_STATUS_SUCCESS" in output.getvalue().decode("utf8")
        except Exception as e:
            return False 
Example #4
Source File: myhttp.py    From wfuzz with GNU General Public License v2.0 5 votes vote down vote up
def _set_extra_options(self, c, fuzzres, poolid):
        if self.pool_map[poolid]["proxy"]:
            ip, port, ptype = next(self.pool_map[poolid]["proxy"])

            fuzzres.history.wf_proxy = (("%s:%s" % (ip, port)), ptype)

            if ptype == "SOCKS5":
                c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5)
            elif ptype == "SOCKS4":
                c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS4)
            elif ptype == "HTTP":
                c.setopt(pycurl.PROXY, "%s:%s" % (ip, port))
            else:
                raise FuzzExceptBadOptions("Bad proxy type specified, correct values are HTTP, SOCKS4 or SOCKS5.")
        else:
            c.setopt(pycurl.PROXY, "")

        mdelay = self.options.get("req_delay")
        if mdelay is not None:
            c.setopt(pycurl.TIMEOUT, mdelay)

        cdelay = self.options.get("conn_delay")
        if cdelay is not None:
            c.setopt(pycurl.CONNECTTIMEOUT, cdelay)

        return c 
Example #5
Source File: updater.py    From marionette with Apache License 2.0 5 votes vote down vote up
def run(self):
        with open(self.dst_path_, 'w+b') as fh:
            c = pycurl.Curl()
            c.setopt(pycurl.URL, self.src_url_)
            c.setopt(c.WRITEDATA, fh)
            if self.socks_ip_ and self.socks_port_:
                c.setopt(pycurl.PROXY, self.socks_ip_)
                c.setopt(pycurl.PROXYPORT, self.socks_port_)
                c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS4)
            c.perform()

        return self.dst_path_ 
Example #6
Source File: mycurl.py    From QMusic with GNU Lesser General Public License v2.1 4 votes vote down vote up
def get(self,
            url,
            header=None,
            proxy_host=None,
            proxy_port=None,
            cookie_file=None):
        '''
        open url width get method
        @param url: the url to visit
        @param header: the http header
        @param proxy_host: the proxy host name
        @param proxy_port: the proxy port
        '''
        crl = pycurl.Curl()
        #crl.setopt(pycurl.VERBOSE,1)
        crl.setopt(pycurl.NOSIGNAL, 1)

        # set proxy
        # crl.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5)

        rel_proxy_host = proxy_host or self.proxy_host
        if rel_proxy_host:
            crl.setopt(pycurl.PROXY, rel_proxy_host)

        rel_proxy_port = proxy_port or self.proxy_port
        if rel_proxy_port:
            crl.setopt(pycurl.PROXYPORT, rel_proxy_port)

            # set cookie
        rel_cookie_file = cookie_file or self.cookie_file
        if rel_cookie_file:
            crl.setopt(pycurl.COOKIEFILE, rel_cookie_file)
            crl.setopt(pycurl.COOKIEJAR, rel_cookie_file)

            # set ssl
        crl.setopt(pycurl.SSL_VERIFYPEER, 0)
        crl.setopt(pycurl.SSL_VERIFYHOST, 0)
        crl.setopt(pycurl.SSLVERSION, 3)

        crl.setopt(pycurl.CONNECTTIMEOUT, 10)
        crl.setopt(pycurl.TIMEOUT, 300)
        crl.setopt(pycurl.HTTPPROXYTUNNEL, 1)

        rel_header = header or self.header
        if rel_header:
            crl.setopt(pycurl.HTTPHEADER, rel_header)

        crl.fp = StringIO.StringIO()

        if isinstance(url, unicode):
            url = str(url)
        crl.setopt(pycurl.URL, url)
        crl.setopt(crl.WRITEFUNCTION, crl.fp.write)
        try:
            crl.perform()
        except Exception, e:
            raise CurlException(e)