From: Nicolas Boisselier Date: Tue, 18 Apr 2023 00:17:40 +0000 (+0200) Subject: sys_interfaces_all() new X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=ecd3801ad09cf295637bdbef5d09948de5fe9131;p=nb.git sys_interfaces_all() new --- diff --git a/etc/profile.d/sys.sh b/etc/profile.d/sys.sh index ec8d40b1..17710461 100644 --- a/etc/profile.d/sys.sh +++ b/etc/profile.d/sys.sh @@ -205,25 +205,18 @@ sys_interfaces() { } sys_interfaces_all() { -( - if which ip > /dev/null; then - ip link | awk -F'(: )|@' '/^[^ ]/{print $2}' - - elif which ifconfig > /dev/null; then - #ifconfig | awk '/^[^ ]/{print $1}' - ifconfig | awk '/^[a-z][^:]+: flags=[0-9]+<[A-Z]+,BROADCAST/{sub(":$","",$1);print $1}' - - fi -) | awk '!x[$0]++ && $1 !~ /^(lo)$/ {print}' | while read int; do - - infos=$( (ip addr show "$int" || ifconfig "$int") 2> /dev/null ) - - mac=$(echo "$infos" | awk '/ether ([^ ]+)/{print $2}') - [ -z "$mac" ] && continue - ip=$(echo "$infos" | awk '/^[\t ]*inet /{sub("^[^0-9]*","",$2); sub("/[0-9]+","",$2); {print $2; exit; printf $2" "}}') - - printf '%s\t%s\t%s\n' "$int" "$mac" "$ip" -done + ip -d -j a | sed "s/ifindex/\nifindex/g" | awk '\ +BEGIN{i=0; j=0}\ +/"link_type":"loopback"/{next}\ +/"info_kind":"veth"/{next}\ +0{print $0; next} +i!=j{print ""}\ +/"ifname":/{i++}\ +match($0, /"ifname":"([^"]+)"/, m) {printf "%s\t", m[1]}\ +match($0, /"address":"([^"]+)"/, m) {printf "%s\t", m[1]}\ +match($0, /"local":"([0-9\.]+)"/, m) {printf "%s", m[1]}\ +0{print "";print i} +' } sys_ips() {