I have this piece of code which is a simple code to create and/or extend a circuit in TOR using stem.
import getpass
import sys
import argparse
import stem
import stem.connection
from stem.control import Controller
if __name__ == '__main__':
try:
controller = Controller.from_port()
except stem.SocketError as exc:
print("Unable to connect to tor on port 9051: %s" % exc)
sys.exit(1)
try:
controller.authenticate()
except stem.connection.MissingPassword:
pw = getpass.getpass("Controller password: ")
try:
controller.authenticate(password = pw)
except stem.connection.PasswordAuthFailed:
print("Unable to authenticate, password is incorrect")
sys.exit(1)
except stem.connection.AuthenticationFailure as exc:
print("Unable to authenticate: %s" % exc)
sys.exit(1)
controller.extend_circuit('0')
controller.extend_circuit('0')
print("Tor is running version %s" % controller.get_network_statuses())
for entry in controller.get_network_statuses():
print (entry)
parser = argparse.ArgumentParser()
parser.add_argument("-hopno", "--hopno", help="Number of hops btw nodes")
known_args = parser.parse_known_args()
#print(known_args)
controller.close()
What I want is to build the circuit step by step (for example in the first step from client to first hop then continue to next hop)
How may I achieve this goal.Thank you in advance.