Created
October 27, 2015 17:11
-
-
Save savon-noir/ebc5ac42153001a5229c to your computer and use it in GitHub Desktop.
Pyton parser for TOR exit nodes published list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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