I'm trying to change Tor IP every 5 seconds with stem to no avail, the IP is always the same.
I mostly followed this answer but I'm not sure if everything is setup correctly. My torrc file (windows 10) looks like this:
ControlPort 9051
## If you enable the controlport, be sure to enable one of these
## authentication methods, to prevent attackers from accessing it.
HashedControlPassword 16:05834BCEDD478D1060F1D7E2CE98E9C13075E8D3061D702F63BCD674DE
And I need Tor Browser opened for the code below to work, is that normal or it's a sign of some misconfiguration?
import requests
import time
from stem import Signal
from stem.control import Controller
# signal TOR for a new connection
def changeIP():
with Controller.from_port(port = 9051) as controller:
controller.authenticate(password="password")
controller.signal(Signal.NEWNYM)
print("IP switched")
# new tor session
tor_session = requests.session()
tor_session.proxies = {}
tor_session.proxies['http'] = 'socks5h://127.0.0.1:9150'
tor_session.proxies['https'] = 'socks5h://127.0.0.1:9150'
for i in range(5):
# check IP from tor session
r = tor_session.get('http://httpbin.org/ip')
print(r.text)
time.sleep(5)
changeIP()