The following is the GNU All-permissive License as recommended in

Copyright (C) 2024 Free Software Foundation

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

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 ...


#! /usr/bin/env python3

import re
import sys
import hashlib

for line in sys.stdin:

    match ="(.* 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:

./ < input.log | tee output.log