Skip to content

Instantly share code, notes, and snippets.

@fchevitarese
Created October 14, 2015 13:01
Show Gist options
  • Save fchevitarese/6d7012778dd06c745e5a to your computer and use it in GitHub Desktop.
Save fchevitarese/6d7012778dd06c745e5a to your computer and use it in GitHub Desktop.
ipclean.py
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