Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. import pycurl
  2. import io
  3.  
  4. import stem.process
  5.  
  6. from stem.util import term
  7.  
  8. SOCKS_PORT = 9150
  9.  
  10.  
  11. def query(url):
  12.   """
  13.  Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
  14.  """
  15.  
  16.   output = io.StringIO()
  17.  
  18.   query = pycurl.Curl()
  19.   query.setopt(pycurl.URL, url)
  20.   query.setopt(pycurl.PROXY, '127.0.0.1')
  21.   query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
  22.   query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
  23.   query.setopt(pycurl.WRITEFUNCTION, output.write)
  24.  
  25.   try:
  26.     query.perform()
  27.     return output.getvalue()
  28.   except pycurl.error as exc:
  29.     return "Unable to reach %s (%s)" % (url, exc)
  30.  
  31.  
  32. # Start an instance of Tor configured to only exit through Russia. This prints
  33. # Tor's bootstrap information as it starts. Note that this likely will not
  34. # work if you have another Tor instance running.
  35.  
  36. def print_bootstrap_lines(line):
  37.   if "Bootstrapped " in line:
  38.     print(term.format(line, term.Color.BLUE))
  39.  
  40.  
  41. print(term.format("Starting Tor:\n", term.Attr.BOLD))
  42.  
  43. tor_process = stem.process.launch_tor_with_config(
  44.   config = {
  45.     'SocksPort': str(SOCKS_PORT),
  46.     #'ExitNodes': '{ru}',
  47.   },
  48.   init_msg_handler = print_bootstrap_lines,
  49. )
  50.  
  51. print(term.format("\nChecking our endpoint:\n", term.Attr.BOLD))
  52. print("RESULT : " + query("http://google.com"))
  53. #print(term.format(query("http://www.priler.com/ip.php"), term.Color.BLUE))
  54.  
  55. tor_process.kill()  # stops tor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement