#!/usr/bin/python # Name : tor-nodes.py # Description: prints a list of IP addresses belonging to # tor nodes by quering TOR client. For this # script to work you must have TorCtl.py available # in the current directory. # Author : iphelix import socket import TorCtl #Connect to TOR try: s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(("localhost",9051)) c = TorCtl.Connection(s) c.authenticate() except socket.error, e: print "[!] Couldn't connect to TOR.",e print "[?] You must enable TOR control port by running" print " 'tor -controlport 9051' from the command line" print " or by editing torrc to enable control port" sys.exit(-1) #Query exit nodes orouters = c.get_network_status() for orouter in orouters: print str(orouter.ip)