1from stem import CircStatus
2from stem.control import Controller
3
4with Controller.from_port(port = 9051) as controller:
5  controller.authenticate()
6
7  for circ in sorted(controller.get_circuits()):
8    if circ.status != CircStatus.BUILT:
9      continue
10
11    print("")
12    print("Circuit %s (%s)" % (circ.id, circ.purpose))
13
14    for i, entry in enumerate(circ.path):
15      div = '+' if (i == len(circ.path) - 1) else '|'
16      fingerprint, nickname = entry
17
18      desc = controller.get_network_status(fingerprint, None)
19      address = desc.address if desc else 'unknown'
20
21      print(" %s- %s (%s, %s)" % (div, fingerprint, nickname, address))
22