Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib3.contrib.socks import SOCKSProxyManager
- from stem import Signal
- from stem.control import Controller
- # Connect to the control port and request a new identity
- with Controller.from_port(port = 9051) as controller:
- controller.authenticate(password="password that you set in torcc") # Connect to the tor control port with stem
- controller.signal(Signal.NEWNYM) # Request a new identity
- http = SOCKSProxyManager("socks5h://localhost:9050", maxsize=20) # Connect to the TOR service as a socks proxy
- # Make the actually HTTP request with TOR
- req = http.request("GET", "https://api.ipify.org?format=json")
- 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