From 2d37a1ec3e5aee5ed6d942a6eb93fdbf20a08413 Mon Sep 17 00:00:00 2001 From: zador-blood-stained Date: Thu, 3 Aug 2017 16:47:22 +0300 Subject: [PATCH] 30-sysinfo: don't show IPs for virtual interfaces Not tested, may need tests and adjustments before the next release Closes #599 --- .../bsp/common/etc/update-motd.d/30-sysinfo | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/bsp/common/etc/update-motd.d/30-sysinfo b/packages/bsp/common/etc/update-motd.d/30-sysinfo index b77525db4a..d7a56d575e 100755 --- a/packages/bsp/common/etc/update-motd.d/30-sysinfo +++ b/packages/bsp/common/etc/update-motd.d/30-sysinfo @@ -90,11 +90,27 @@ function ambienttemp() { esac } # ambienttemp +#function get_ip_addresses() { +# # return up to 2 IPv4 address(es) comma separated +# hostname -I | tr " " "\n" | \ +# grep -E "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" | \ +# tail -n2 | sed ':a;N;$!ba;s/\n/,/g' +#} # get_ip_addresses + function get_ip_addresses() { - # return up to 2 IPv4 address(es) comma separated - hostname -I | tr " " "\n" | \ - grep -E "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" | \ - tail -n2 | sed ':a;N;$!ba;s/\n/,/g' + local ips=() + for f in /sys/class/net/*; do + local intf=$(basename $f) + # match only interface names starting with e (Ethernet), w (wireless), r (some Ralink drivers use ra format) + if [[ $intf =~ ^[ewr].* ]]; then + local tmp=$(ip -4 addr show dev $intf | awk '/inet/ {print $2}' | cut -d'/' -f1) + # add both name and IP - can be informative but becomes ugly with long persistent/predictable device names + #[[ -n $tmp ]] && ips+=("$intf: $tmp") + # add IP only + [[ -n $tmp ]] && ips+=("$tmp") + fi + done + echo "${ips[@]}" } # get_ip_addresses function storage_info() {