1

Which stem python code would you suggest to determine whether tor is operational (bootstrapped at 100%) or not?

  • As a client or as a relay? – cacahuatl Feb 20 '17 at 22:44
  • As a client, I have edited the post. – user123456 Feb 21 '17 at 9:44
1

You need to query the client bootstrap status. It's done - as it's said in control protocol spec like this:

telnet 127.0.0.1 9051
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
AUTHENTICATE "cleartextpassword"
250 OK
GETINFO status/bootstrap-phase
250-status/bootstrap-phase=NOTICE BOOTSTRAP PROGRESS=100 TAG=done SUMMARY="Done"
250 OK
QUIT
250 closing connection
Connection closed by foreign host.

You need - if using Stem - a Controller class, and the python code doing exactly this will be:

import stem
import stem.connection
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
    controller.authenticate(password = 'cleartextpassword')
    response=controller.get_info("status/bootstrap-phase")
    controller.close()

if(response.find('SUMMARY="Done"') > 0):
    print "bootstrapped OK"
else:
    print "Bootstrap not finished: " + response

Have a good day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.