Python pycurl.PROXY Examples
The following are 16
code examples of pycurl.PROXY().
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 |
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 |
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 |
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: InstagramRegistration.py From Instagram-API with MIT License | 5 votes |
def request(self, endpoint, post=None): buffer = BytesIO() ch = pycurl.Curl() ch.setopt(pycurl.URL, Constants.API_URL + endpoint) ch.setopt(pycurl.USERAGENT, self.userAgent) ch.setopt(pycurl.WRITEFUNCTION, buffer.write) ch.setopt(pycurl.FOLLOWLOCATION, True) ch.setopt(pycurl.HEADER, True) ch.setopt(pycurl.VERBOSE, False) ch.setopt(pycurl.COOKIEFILE, os.path.join(self.IGDataPath, self.username, self.username + "-cookies.dat")) ch.setopt(pycurl.COOKIEJAR, os.path.join(self.IGDataPath, self.username, self.username + "-cookies.dat")) if post is not None: ch.setopt(pycurl.POST, True) ch.setopt(pycurl.POSTFIELDS, post) if self.proxy: ch.setopt(pycurl.PROXY, self.proxyHost) if self.proxyAuth: ch.setopt(pycurl.PROXYUSERPWD, self.proxyAuth) ch.perform() resp = buffer.getvalue() header_len = ch.getinfo(pycurl.HEADER_SIZE) header = resp[0: header_len] body = resp[header_len:] ch.close() if self.debug: print("REQUEST: " + endpoint) if post is not None: if not isinstance(post, list): print("DATA: " + str(post)) print("RESPONSE: " + body) return [header, json_decode(body)]
Example #5
Source File: client.py From pycopia with Apache License 2.0 | 5 votes |
def _set_common(self, c): c.setopt(pycurl.FOLLOWLOCATION, 1) c.setopt(pycurl.AUTOREFERER, 1) c.setopt(pycurl.ENCODING, self._accept_encoding) c.setopt(pycurl.MAXREDIRS, 255) c.setopt(pycurl.CONNECTTIMEOUT, 30) c.setopt(pycurl.TIMEOUT, 300) c.setopt(pycurl.NOSIGNAL, 1) if self._proxy: c.setopt(pycurl.PROXY, self._proxy) if self._url.scheme == 'https': c.setopt(pycurl.SSLVERSION, 3) c.setopt(pycurl.SSL_VERIFYPEER, 0)
Example #6
Source File: test_fetch.py From landscape-client with GNU General Public License v2.0 | 5 votes |
def test_pycurl_proxy(self): """If provided, the proxy is set in the request.""" curl = CurlStub(b"result") proxy = "http://my.little.proxy" result = fetch("http://example.com", curl=curl, proxy=proxy) self.assertEqual(b"result", result) self.assertEqual(proxy.encode('ascii'), curl.options[pycurl.PROXY])
Example #7
Source File: Request.py From wfuzz with GNU General Public License v2.0 | 5 votes |
def setUrl(self, urltmp): self.__variablesGET = VariablesSet() self.schema, self.__host, self.__path, self.__params, variables, f = urlparse(urltmp) if "Host" not in self._headers or (not self._headers["Host"]): self._headers["Host"] = self.__host if variables: self.__variablesGET.parseUrlEncoded(variables) # ############## PROXY ##################################
Example #8
Source File: myhttp.py From wfuzz with GNU General Public License v2.0 | 5 votes |
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 #9
Source File: updater.py From marionette with Apache License 2.0 | 5 votes |
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 #10
Source File: transport.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 5 votes |
def request(self, url, method, body, headers): c = pycurl.Curl() c.setopt(pycurl.URL, str(url)) if 'proxy_host' in self.proxy: c.setopt(pycurl.PROXY, self.proxy['proxy_host']) if 'proxy_port' in self.proxy: c.setopt(pycurl.PROXYPORT, self.proxy['proxy_port']) if 'proxy_user' in self.proxy: c.setopt(pycurl.PROXYUSERPWD, "%(proxy_user)s:%(proxy_pass)s" % self.proxy) self.buf = StringIO() c.setopt(pycurl.WRITEFUNCTION, self.buf.write) #c.setopt(pycurl.READFUNCTION, self.read) #self.body = StringIO(body) #c.setopt(pycurl.HEADERFUNCTION, self.header) if self.cacert: c.setopt(c.CAINFO, str(self.cacert)) c.setopt(pycurl.SSL_VERIFYPEER, self.cacert and 1 or 0) c.setopt(pycurl.SSL_VERIFYHOST, self.cacert and 2 or 0) c.setopt(pycurl.CONNECTTIMEOUT, self.timeout/6) c.setopt(pycurl.TIMEOUT, self.timeout) if method=='POST': c.setopt(pycurl.POST, 1) c.setopt(pycurl.POSTFIELDS, body) if headers: hdrs = ['%s: %s' % (str(k), str(v)) for k, v in headers.items()] ##print hdrs c.setopt(pycurl.HTTPHEADER, hdrs) c.perform() ##print "pycurl perform..." c.close() return {}, self.buf.getvalue()
Example #11
Source File: reqresp.py From wfuzz with GNU General Public License v2.0 | 5 votes |
def setUrl (self, urltmp): self.__variablesGET=VariablesSet() self.schema,self.__host,self.__path,self.__params,variables,f=urlparse(urltmp) self.__headers["Host"]=self.__host if variables: self.__variablesGET.parseUrlEncoded(variables) ############### PROXY ##################################
Example #12
Source File: mycurl.py From QMusic with GNU Lesser General Public License v2.1 | 4 votes |
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)
Example #13
Source File: mycurl.py From QMusic with GNU Lesser General Public License v2.1 | 4 votes |
def post(self, url, data, header=None, proxy_host=None, proxy_port=None, cookie_file=None): ''' open url width post method @param url: the url to visit @param data: the data to post @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 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() crl.setopt(crl.POSTFIELDS, data) # post data 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)
Example #14
Source File: mycurl.py From QMusic with GNU Lesser General Public License v2.1 | 4 votes |
def upload(self, url, data, header=None, proxy_host=None, proxy_port=None, cookie_file=None): ''' open url with upload @param url: the url to visit @param data: the data to upload @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 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(pycurl.HTTPPOST, data) # upload file crl.setopt(crl.WRITEFUNCTION, crl.fp.write) try: crl.perform() except Exception, e: raise CurlException(e)
Example #15
Source File: analyze_packages.py From pyCAF with GNU General Public License v3.0 | 4 votes |
def get_rh_sso(self): """ Function wich used login and password to connect at www.redhat.com and return the "rh_sso" proxy used for request authentication. """ self._logger.debug("RHEL rh_sso getting in progress...") username = self.config_server.redhat["login_username"] password = self.config_server.redhat["login_pass"] url = 'https://www.redhat.com/wapps/sso/login.html' values={'username':username,'password':password,'_flowId':'legacy-login-flow','redirect':'https://www.redhat.com/wapps/ugc/protected/account.html','failureRedirect':'http://www.redhat.com/wapps/sso/login.html'} data_post = urllib.urlencode(values) headers = Storage() c = pycurl.Curl() c.setopt(pycurl.URL, url) #============================================================================== # DEBUG comments in order to use the Burp Proxy software #============================================================================== #c.setopt(pycurl.PROXY, '127.0.0.1') #c.setopt(pycurl.PROXYPORT, 8080) #c.setopt(pycurl.SSL_VERIFYPEER, 1) #c.setopt(pycurl.SSL_VERIFYHOST, 2) #c.setopt(pycurl.CAINFO, "/home/thierry/Divers/Burp/cacert.crt") #============================================================================== c.setopt(pycurl.USERAGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0") c.setopt(pycurl.HTTPHEADER, ['Accept-Language: en-US,en;q=0.5', 'Connection: keep-alive', 'www.whitehouse.gov: 200']) c.setopt(pycurl.POST, 1) c.setopt(pycurl.POSTFIELDS, data_post) c.setopt(c.HEADERFUNCTION, headers.store) c.perform() c.close() headers = str(headers) expression = r"(?P<var1>.*)(?P<rh_sso>Set-Cookie: rh_sso=)(?P<sso_key>(?!\").*?)(?P<end>;)" header_lines = headers.split('\n') for head in header_lines: result_re = re.match(expression, head) if result_re is not None: sso_key = "rh_sso=" + str(result_re.group('sso_key')) self._logger.debug("rh_sso value : "+ str(sso_key)) return sso_key
Example #16
Source File: reqresp.py From darkc0de-old-stuff with GNU General Public License v3.0 | 4 votes |
def perform(self): self.__performHead="" self.__performBody="" conn=pycurl.Curl() conn.setopt(pycurl.SSL_VERIFYPEER,False) conn.setopt(pycurl.SSL_VERIFYHOST,1) conn.setopt(pycurl.URL,self.completeUrl) if self.__method or self.__userpass: if self.__method=="basic": conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC) elif self.__method=="ntlm": conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_NTLM) elif self.__method=="digest": conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_DIGEST) conn.setopt(pycurl.USERPWD, self.__userpass) if self.__timeout: conn.setopt(pycurl.CONNECTTIMEOUT, self.__timeout) conn.setopt(pycurl.NOSIGNAL, 1) if self.__totaltimeout: conn.setopt(pycurl.TIMEOUT, self.__totaltimeout) conn.setopt(pycurl.NOSIGNAL, 1) conn.setopt(pycurl.WRITEFUNCTION, self.body_callback) conn.setopt(pycurl.HEADERFUNCTION, self.header_callback) if self.__proxy!=None: conn.setopt(pycurl.PROXY,self.__proxy) if self.__headers.has_key("Proxy-Connection"): del self.__headers["Proxy-Connection"] conn.setopt(pycurl.HTTPHEADER,self.__getHeaders()) if self.method=="POST": conn.setopt(pycurl.POSTFIELDS,self.__postdata) conn.perform() rp=Response() rp.parseResponse(self.__performHead) rp.addContent(self.__performBody) self.response=rp ######### ESTE conjunto de funciones no es necesario para el uso habitual de la clase