1

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

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

1 Answer 1

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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .