Created
October 14, 2015 13:01
-
-
Save fchevitarese/833340bf3e649953b66b to your computer and use it in GitHub Desktop.
ipclean.py
This file contains hidden or 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
import itertools | |
import re | |
iplist = [] | |
with open('level3.db.new') as myfile: | |
for line in myfile.readlines(): | |
if line.startswith('member'): | |
iplist.append(re.findall(r'[0-9]+(?:\.[0-9]+){3}(?:\/[0-9]+)', line)) | |
ipclean = [ip for ip in iplist if ip] | |
merged = list(itertools.chain.from_iterable(ipclean)) | |
with open('tmp.txt', 'w') as myfile: | |
for ip in merged: | |
myfile.write(ip + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment