Skip to content

Instantly share code, notes, and snippets.

@savon-noir
Created October 27, 2015 17:11
Show Gist options
  • Save savon-noir/ebc5ac42153001a5229c to your computer and use it in GitHub Desktop.
Save savon-noir/ebc5ac42153001a5229c to your computer and use it in GitHub Desktop.
Pyton parser for TOR exit nodes published list
# -*- coding: utf-8 -*-
#
# get file from https://check.torproject.org/exit-addresses
def parse_torexitnodes(fileobj):
torlist = []
btemplate = {
'nodename': '',
'create_date': '',
'last_update': '',
'ip': ''
}
for fline in fileobj:
if fline.startswith('ExitNode'):
bdict = btemplate.copy()
bdict['nodename'] = fline.split()[1]
elif fline.startswith('Published'):
bdict['create_date'] = ' '.join(fline.split()[1:])
elif fline.startswith('LastStatus'):
bdict['last_update'] = ' '.join(fline.split()[1:])
elif fline.startswith('ExitAddress'):
bdict['ip'] = fline.split()[1]
torlist.append(bdict)
return torlist
try:
with open('exit-addresses', 'r') as fileobj:
torlist = parse_torexitnodes(fileobj)
for t in torlist:
print t
print "-----------------"
except IOError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment