Tor browser, new IP not working?

后端 未结 1 1831
囚心锁ツ
囚心锁ツ 2021-01-26 07:19

I am trying to use tor browser, and get a new IP address each URL I visit in python. I am able to open an instance of selenium running the tor browser, but how can I request a

相关标签:
1条回答
  • 2021-01-26 08:03

    To use Python to request a new IP for every request, you need to open a connection to the ControlPort and issue a NEWNYM signal.

    You can use Stem to simplify the connection and commands:

    from stem.control import Controller
    from stem import Signal
    
    if __name__ == '__main__':
      with Controller.from_port(port = 9051) as controller:
        controller.authenticate('password')  # provide the password here if you set one
    
        controller.signal(Signal.NEWNYM) # switch to clean circuits
    

    Keep in mind Tor may rate limit NEWNYM requests so you may need to wait a short while (default 10 seconds) before issuing that command. Also, due to the limited number of exit nodes, your circuits might get the same exit node depending on how many requests you are issuing.

    You need to issue this command every time you want to get a new IP (switch circuits).

    0 讨论(0)
提交回复
热议问题