Created
September 21, 2016 16:42
-
-
Save sheeley/70f5ec33ebc7dd1c8d925fab1b81a7f0 to your computer and use it in GitHub Desktop.
IP Cleaner
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
# Scrubs a file of ip addresses, renaming anything that isn't broadcast to 10.0.0.(1-n) | |
import re | |
import sys | |
pattern = '(?:[0-9]{1,3}\.){3}[0-9]{1,3}' | |
def main(): | |
with open('output.txt', 'r') as output_file: | |
output = output_file.read() | |
# print output | |
found = re.findall(pattern, output) | |
uniques = set([f for f in found if not f.startswith('255')]) | |
idx = 1 | |
for u in uniques: | |
output = output.replace(u, '10.0.0.%s' % idx) | |
idx += 1 | |
print output | |
if __name__ == '__main__': | |
sys.exit(int(main() or 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment