Advertisement
Guest User

TOR python

a guest
Feb 20th, 2021
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. from urllib3.contrib.socks import SOCKSProxyManager
  2. from stem import Signal
  3. from stem.control import Controller
  4.  
  5. # Connect to the control port and request a new identity
  6. with Controller.from_port(port = 9051) as controller:
  7. controller.authenticate(password="password that you set in torcc") # Connect to the tor control port with stem
  8. controller.signal(Signal.NEWNYM) # Request a new identity
  9. http = SOCKSProxyManager("socks5h://localhost:9050", maxsize=20) # Connect to the TOR service as a socks proxy
  10.  
  11. # Make the actually HTTP request with TOR
  12. req = http.request("GET", "https://api.ipify.org?format=json")
  13. print(req.data.decode("utf-8")) # Get string from request data byte array (TOR may not issue a new identity if its within
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement