def start_controller(self): try: control = stem.control.Controller.from_port(address='127.0.0.1', port=9051) control.authenticate() return True except stem.SocketError: return False
def controller(): """ Provides a Controller for our tor instance. This starts tor if it isn't already running. """ if not is_running(): start() control = stem.control.Controller.from_port(control_port=CONTROL_PORT) control.authenticate() return control
def renew_ip(port=9051, passwd=None): passwd = passwd or 'password' with stem.control.Controller.from_port(port=port) as control: control.authenticate(password=passwd) control.signal(stem.Signal.NEWNYM) time.sleep(5)