I'm writing a script to extract information from BusyBox v1.25.1/Linux 2.6.36/router where the user can simply run the script and copy/paste the output into a submission form to request support. The script it's essentially a list of commands like route
, ifconfig
, etc. Because of the busybox implication I'm restricted to /bin/sh.
I'm trying to find a smart way to automatically mask all the public IP addresses only from the output. Replace the full IP would be already good but if it's possible I would be looking for a command to pipe at the end of each command (even an internal function) to simply replace let's say the first two octects e.g.
80.80.80.80
with
XX.XX.80.80
A nice to have feature would be to replace the same number of digits to retain formatting where possible. e.g.
8.8.8.8=X.X.X.X
80.80.8.8=XX.XX.X.X
180.180.80.8=XXX.XXX.XX.X
practical example:
root@router:/proc# route | filtering-goes-here
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
XX.XX.168.1 * 255.255.255.255 UH 0 0 0 vlan2
172.16.9.0 * 255.255.255.0 U 0 0 0 br1
10.10.9.0 * 255.255.255.0 U 0 0 0 br0
10.114.126.0 * 255.255.254.0 U 0 0 0 tun11
XX.XX.168.0 * 255.255.252.0 U 0 0 0 vlan2
10.10.0.0 * 255.255.0.0 U 0 0 0 tinc
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default cpc86269 0.0.0.0 UG 0 0 0 vlan2
Thanks!!