Created
July 18, 2013 01:20
-
-
Save collina/6025993 to your computer and use it in GitHub Desktop.
A few of Tor's exonerator.py functionalities written into a module.
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
#!/usr/bin/env python | |
# A modification by @CDA of The Tor Project's exonerator.py (Copyright 2009) -- see LICENSE for licensing information | |
import binascii | |
import os | |
import sys | |
import time | |
from optparse import OptionParser | |
from IPy import IP | |
class lookup: | |
def __init__(self, archive = 'data/descriptors/'): | |
self.DELIMITER = "-" * 75 | |
self.dictionary = {} | |
self.archive_directory = os.path.dirname(archive) | |
consensus_files = list() | |
for directories in os.listdir(self.archive_directory): | |
if directories.startswith("consensuses-"): | |
directories_path = os.path.join(archive, directories) | |
for dayfile in os.listdir(directories_path): | |
directories_path_2 = os.path.join(archive, directories, dayfile) | |
for filename in os.listdir(directories_path_2): | |
entry = "%s/%s" % (directories_path_2, filename) | |
consensus_files.append(entry) | |
if not consensus_files: | |
return None | |
for consensus in consensus_files: | |
consensus_handler = open(consensus, "r") | |
line = consensus_handler.readline() | |
while line: | |
if line.startswith("r "): | |
date = time.strptime(line.split(" ")[4], "%Y-%m-%d") | |
address = IP(line.split(" ")[6]) | |
if address not in self.dictionary: self.dictionary[address] = set() | |
self.dictionary[address].add(date) | |
line = consensus_handler.readline() | |
consensus_handler.close() | |
def search(self, address, time = None): | |
returned_result = { | |
'result' : False, | |
'message' : None | |
} | |
try: | |
address = IP(address) | |
except ValueError: | |
parser.error("invalid IP address in question: '%s'" % args[0]) | |
if address in self.dictionary: | |
returned_result['result'] = True | |
else: | |
returned_result['result'] = False | |
for exit_nodes in self.dictionary.keys(): | |
if exit_nodes.overlaps(IP("%s/24" % address, make_net=True)): | |
returned_result['message'] = 'same_block' | |
return returned_result | |
if __name__ == "__main__": | |
rawr = lookup() | |
print rawr.search('85.214.192.251') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment