Last active
December 8, 2015 13:30
-
-
Save tmshv/9c0712b858ab1bbed976 to your computer and use it in GitHub Desktop.
Stem usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socks | |
import socket | |
from stem import Signal | |
from stem.control import Controller | |
control_port = 9051 | |
proxy_port = 9050 | |
proxy_host = 'localhost' | |
tor = Controller.from_port(port=control_port) | |
tor.authenticate() | |
socks.set_default_proxy(socks.SOCKS5, proxy_host, proxy_port) | |
socket.socket = socks.socksocket | |
def new_tor_circuit(): | |
tor.signal(Signal.NEWNYM) | |
if __name__ == '__main__': | |
import requests | |
from time import sleep | |
while True: | |
for i in range(5): | |
ip = requests.get('https://api.ipify.org?format=text').text | |
print(ip) | |
sleep(10) | |
new_tor_circuit() | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment