Skip to content

Instantly share code, notes, and snippets.

@r000t
Created July 10, 2014 00:54
Show Gist options
  • Save r000t/ea5e149bec3ec45fb8ac to your computer and use it in GitHub Desktop.
Save r000t/ea5e149bec3ec45fb8ac to your computer and use it in GitHub Desktop.
Python module that grabs a list of Tor exits and checks IPs against the list
#!/usr/bin/python
import urllib2
def fetch():
# Just a quick note: I feel there's no reason to blanket ban relay nodes.
# A person runs a relay node as opposed to an exit to avoid the backlash
# normally associated with running an exit. Relay operators shouldn't be
# be punsihed for doing literally the least they can do to help out.
#
# I'm not against Tor, but it's just not "for" certain things, due to abuse.
#
# So, long story short, this only returns exits.
# Also, it doesn't take exit policies into account.
# It's a little hamhanded, but it's dead simple to implement.
lists = ['http://torstatus.blutmagie.de/',
'https://torstatus.rueckgr.at/',
'http://tns.hermetix.org/']
allexits = []
for exitlist in lists:
for line in urllib2.urlopen(exitlist + "ip_list_exit.php/Tor_ip_list_EXIT.csv"):
thisexit = line.replace('\n','')
if thisexit not in allexits:
allexits.append(thisexit)
return allexits
def checkip(address):
#Global variable prevents secondary scrapes for subsequent checks.
#Scrape will happen again next time the script runs.
#Pickle the result if you want to save it for later.
global exits
try: #If doing something to the variable fails, it doesn't exist
garbage = type(exits)
except NameError: #It failed. Let's make it exist.
exits = fetch()
return address in exits
if __name__ == "__main__":
print 'Getting exits, this might take some time...'
allexits = fetch()
for exit in allexits:
print exit
print 'There are currently ' + str(len(allexits)) + ' Tor exit nodes.'
print 'Also...'
while True:
if checkip(raw_input('Enter an IP and I\'ll check it against the list: ')):
print 'Yes, that\'s a Tor exit.'
else:
print 'No, that is not a Tor exit.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment