Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pycurl
- import io
- import stem.process
- from stem.util import term
- SOCKS_PORT = 9150
- def query(url):
- """
- Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
- """
- output = io.StringIO()
- query = pycurl.Curl()
- query.setopt(pycurl.URL, url)
- query.setopt(pycurl.PROXY, '127.0.0.1')
- 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.
- def print_bootstrap_lines(line):
- if "Bootstrapped " in line:
- print(term.format(line, term.Color.BLUE))
- print(term.format("Starting Tor:\n", term.Attr.BOLD))
- tor_process = stem.process.launch_tor_with_config(
- config = {
- 'SocksPort': str(SOCKS_PORT),
- #'ExitNodes': '{ru}',
- },
- init_msg_handler = print_bootstrap_lines,
- )
- print(term.format("\nChecking our endpoint:\n", term.Attr.BOLD))
- print("RESULT : " + query("http://google.com"))
- #print(term.format(query("http://www.priler.com/ip.php"), term.Color.BLUE))
- tor_process.kill() # stops tor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement