Created
January 25, 2025 08:28
-
-
Save Davis-3450/58ea23a97af563223aaa1455fad06278 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from stem import Signal | |
from stem.control import Controller | |
import requests | |
class TorController: | |
def __init__(self, control_port=9051): | |
self.control_port = control_port | |
self.local_ip = f"127.0.0.1{control_port}" | |
def change_route(self): | |
with Controller.from_port(port=self.control_port) as controller: | |
controller.authenticate() | |
controller.signal(Signal.NEWNYM) | |
def get_ip(self): | |
print(requests.get("http://httpbin.org/ip", proxy=self.local_ip)) | |
tor_controller = TorController() | |
tor_controller.change_route() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment