Skip to content

Instantly share code, notes, and snippets.

@sheeley
Created September 21, 2016 16:42
Show Gist options
  • Save sheeley/70f5ec33ebc7dd1c8d925fab1b81a7f0 to your computer and use it in GitHub Desktop.
Save sheeley/70f5ec33ebc7dd1c8d925fab1b81a7f0 to your computer and use it in GitHub Desktop.
IP Cleaner
# 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