#!/usr/bin/env python """ getTorExitNode.py Rev 1.0 Sebastien Damaye (www.aldeid.com) 2011-02-09 --- This program aims at providing torproxy with a valid Tor exit node. (Tortunnel can be downloaded here: http://www.thoughtcrime.org/software/tortunnel/) It returns one or all valid exit nodes (Nodes must fulfill all filtering conditions: exit, fast, valid and stable.) For a usage example, go to: http://www.aldeid.com/index.php/Tor/Usage/Nmap-scan-through-tor Usage: ./getTorExitNode.py [--all] Options: --all Get all valid exit nodes Without the --all option, first valid exit node is returned --- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ import urllib import sys from optparse import OptionParser class Tor: def __init__(self, allnodes): self.allnodes = allnodes def getTorNodes(self): f = urllib.urlopen('http://128.31.0.34:9031/tor/status/all') print "Valid Tor exit node(s) found:" for i in f: if i.startswith('r '): line = i if i.startswith('s Exit') \ and 'Fast' in i \ and 'Stable' in i \ and 'Valid' in i: print line.split(" ")[6] if not self.allnodes: break if __name__ == '__main__': usage = "usage: %prog [--all]" parser = OptionParser(usage) parser.add_option("--all", action="store_true", dest="allnodes", default=False, help="Return all valid Tor exit nodes") (options, args) = parser.parse_args(sys.argv) oTor = Tor(options.allnodes) oTor.getTorNodes() del oTor