Skip to content

Instantly share code, notes, and snippets.

@bigtonylewis
Created January 26, 2020 09:12
Show Gist options
  • Save bigtonylewis/ccf7c7a3ec980407947901208c564571 to your computer and use it in GitHub Desktop.
Save bigtonylewis/ccf7c7a3ec980407947901208c564571 to your computer and use it in GitHub Desktop.
Obfuscate the output of `ip route` when reporting bugs
import re
import random
# let's say your iproute contains this as the output of `ip route`
iproute = '''
default dev ppp0 scope link
10.167.0.1 via 10.167.0.168 dev tun-alpha
10.167.0.168 dev tun-alpha proto kernel scope link src 10.167.0.237
10.100.159.0/24 dev wg-theta proto kernel scope link src 10.100.159.179
10.193.230.0/24 via 10.100.159.1 dev wg-theta
10.153.1.0/24 dev enp2s0f0 proto kernel scope link src 10.153.1.1 metric 100
10.153.179.0/24 dev lxdbr0 proto kernel scope link src 10.153.179.1
133.159.238.101 dev ppp0 proto kernel scope link src 133.159.203.189
169.254.0.0/16 dev wg-theta scope link metric 1000
'''
ips = re.findall(r'\d+\.\d+\.\d+\.\d+', iproute)
octets = set()
for ip in ips:
for octet in ip.split('.'):
octets.add(octet)
mapping = {}
for octet in octets:
mapping[octet] = '{}'.format(random.randint(100,253))
# overwrite the ones we want to preserve, like private IP ranges
fixedmapping = {
'10': '10',
'192': '192',
'168': '168',
'0': '0',
'169': '169',
'254': '254',
'1': '1'
}
for octet in fixedmapping.keys():
mapping[octet] = fixedmapping[octet]
# now do these substitutions of octets inside the IP address strings themselves
ipmapping = {}
for ip in ips:
ipmapping[ip] = '.'.join([mapping[octet] for octet in ip.split('.')])
# contains a mapping of things we want to change, like interface names
globalmapping = {
'tun-alpha': 'tun0',
'wg-theta': 'wg0'
}
# replace the IPs back in the original iproute string
for ip in ips:
iproute = iproute.replace(ip, ipmapping[ip])
# obfuscate the global mapping
for s in globalmapping.keys():
iproute = iproute.replace(s, globalmapping[s])
print(iproute)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment