""" NetDB scraping code This is used to obtain a list of IPs from our local NetDB cache. The RegEX needs some work. Coded by Adrian Crenshaw Please excuse the sloppiness of the code, I've only recently began to learn Python http://irongeek.com """ # import sys import urllib2 import threading from threading import Thread import time from datetime import datetime import string import os import re #ScanStartedTime = string.replace(string.replace(str(datetime.now())," ", "-"),":","-") #OutputFile=open('temp-router-ips-' + ScanStartedTime + '.txt', 'wb',1) OutputFile=open('all-sorted-uniq.txt', 'ab',1) netdbdir= 'C:\\Windows\\SysWOW64\\config\\systemprofile\\AppData\\Roaming\\I2P\\netDb\\' for root, dirs, files in os.walk(netdbdir): for afile in files: #print "-----"+ afile +"-----" InputFile = open(netdbdir + afile,'rb') TextBlob= str(InputFile.read()) #help from http://www.regular-expressions.info/examples.html IPsInFile = re.findall('(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',TextBlob) for RouterIP in IPsInFile: OutputFile.write(RouterIP + '\n') InputFile.close() OutputFile.close() TheInput=open("all-sorted-uniq.txt",'r').readlines() Output= sorted(list(set(TheInput))) open("all-sorted-uniq.txt",'wb').writelines(Output)