The following is the GNU All-permissive License as recommended in https://www.gnu.org/licenses/license-recommendations.en.html
Copyright (C) 2024 Free Software Foundation sysadmin@fsf.org
Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.
Contributions are welcome. See https://savannah.gnu.org/maintenance/fsf/.
anonymize log ips
if you want to grab an ip addr from a log, hash it with a salt, then insert that back where the ip was, you can use a script like the following.
log format:
... client my-ip-addr#12345 ...
script:
#! /usr/bin/env python3
import re
import sys
import hashlib
for line in sys.stdin:
match = re.search("(.* client )(.*)(#.*)", line)
start = match.groups()[0]
ip_addr = match.groups()[1]
end = match.groups()[2]
salted_addr = (ip_addr + " salt: change to some random string...").encode('utf-8')
hashed_addr = hashlib.sha256(salted_addr).hexdigest()
#print(ip_addr) # debug
print(start + hashed_addr + end)
running the script:
./anonymize.py < input.log | tee output.log