1

I am currently trying to follow the a script I found online here: Periodic Tor IP Rotation

The code I am trying to use is the following:

import requests
from stem import Signal
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
  controller.authenticate()
  controller.signal(Signal.NEWNYM)
proxies = {
  "http": "http://127.0.0.1:8118"
}
headers = {
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11'
}
r = requests.get("http://icanhazip.com", proxies=proxies, headers=headers)
print(r.text)

However, my ip address doesn't change using this. Does anyone have any idea how I can modify it? Thanks.

user321627
  • 2,350
  • 4
  • 20
  • 43
  • Can you ditch Privoxy and use Tor's SOCKS proxy directly as shown here: https://stackoverflow.com/a/43823166/892493 – drew010 Aug 24 '18 at 23:40
  • Is privoxy not usable in this case? I have little understanding what works. – user321627 Aug 25 '18 at 01:21
  • If you aren't using privoxy for anything except HTTP proxy for Python -> Tor then there's no reason to put it between Tor and Python anymore. A long time ago that's what many examples used because requests did not have SOCSK5h support so it was a necessary layer. Now if you can use requests[socks] then Privoxy is unnecessary. I'm not sure that's why you don't see the IP change between requests but I'd be interested to see if the signal works when you are using Tor's SOCKS proxy directly. – drew010 Aug 25 '18 at 18:15

1 Answers1

1

You need to be give a password to the authenticate() function.

Example:

    with Controller.from_port(port=9051) as controller:
        controller.authenticate(password='tor') # password came from your torrc file
        print("Success!")
        controller.signal(Signal.NEWNYM)
        print("New Tor connection processed")
tom
  • 86
  • 5