#!/usr/local/bin/python3.sh # -*-mode: python; py-indent-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*- # http://vt5hknv6sblkgf22.onion/tutorials/examples/list_circuits.html import sys import os import getpass from stem import CircStatus from tor_controller import get_controller def iMain(): if os.path.exists('/run/tor/control'): controller = get_controller(unix='/run/tor/control') else: controller = get_controller(port=9051) password = os.environ.get('TOR_CONTROLLER_PASSWORD', '') try: controller.authenticate(password) for circ in sorted(controller.get_circuits()): if circ.status != CircStatus.BUILT: continue print("") print("Circuit %s (%s)" % (circ.id, circ.purpose)) for i, entry in enumerate(circ.path): div = '+' if (i == len(circ.path) - 1) else '|' fingerprint, nickname = entry desc = controller.get_network_status(fingerprint, None) address = desc.address if desc else 'unknown' print(" %s- %s (%s, %s)" % (div, fingerprint, nickname, address)) except Exception as e: print(e) finally: del controller return 0 if __name__ == '__main__': sys.exit( iMain() )