interface names
Not every distribution uses the same interface names. Instead of eth0, I have enp2s0. Instead of providing the wlan0 and eth0 addresses, the script could loop over all network interfaces in /sys/class/net (except lo interface).
That way, if you have multiple ethernet interfaces or multiple wlan, you get them all. This is also pulling ipv6 address, but so does your original code. You collapse 2nd line with first when you echo without quotes.
$ for i in `ls /sys/class/net`;
do
echo "===$i==="
ip addr list $i | grep inet |cut -d' ' -f6|cut -d/ -f1
done
===eno1===
===enp2s0===
192.168.??.??
????::???:????:????:???
===lo===
127.0.0.1
::1
This wasn't meant to be distro agnostic, but I might work towards it. Thanks!
Yeah. It's really cool that you shared your idea in either case, so thank you! I hadn't thought of something like this so it was fun to make it work in my own environment :)