Which stem python code would you suggest to determine whether tor is operational (bootstrapped at 100%) or not?
1 Answer
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!