Created
March 13, 2017 16:32
-
-
Save xai/9f45c65fe9653fa59047cd9a97581bc1 to your computer and use it in GitHub Desktop.
Anonymize logfiles
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# vim:fenc=utf-8 | |
# | |
# Copyright © 2017 Olaf Lessenich <xai@linux.com> | |
# | |
# Distributed under terms of the MIT license. | |
""" | |
Anonymize logfiles | |
""" | |
import re | |
import sys | |
def anon(s): | |
return ('[ANONYMIZED %s]' % s.upper()) | |
regexes = dict() | |
regexes['mail'] = re.compile(r"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)") | |
regexes['ip'] = re.compile(r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})") | |
for line in sys.stdin: | |
for name, regex in regexes.items(): | |
line = regex.sub(anon(name), line) | |
sys.stdout.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment