diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-12-28 16:13:03 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-12-28 16:20:51 +0100 |
commit | bbc2a15795bfbe11febe8c00d2a592ba5cf8daf5 (patch) | |
tree | 47054ffca1f9c3e3f507356d38f3b3bbc9571340 /src/completion/list_local_ips.sh | |
parent | 9f459cb1185af7dd7fe3104b2fb047add69938cd (diff) | |
download | vyos-1x-bbc2a15795bfbe11febe8c00d2a592ba5cf8daf5.tar.gz vyos-1x-bbc2a15795bfbe11febe8c00d2a592ba5cf8daf5.zip |
xml: completion-help: add helper for all local assigned IP addresses
This replaces the Python script by a bash variant which is much faster as the
Python interpreter does not need to be launched on invocation.
Diffstat (limited to 'src/completion/list_local_ips.sh')
-rwxr-xr-x | src/completion/list_local_ips.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/completion/list_local_ips.sh b/src/completion/list_local_ips.sh new file mode 100755 index 000000000..a506ce16e --- /dev/null +++ b/src/completion/list_local_ips.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +ipv4=0 +ipv6=0 + +while [[ "$#" -gt 0 ]]; do + case $1 in + -4|--ipv4) ipv4=1 ;; + -6|--ipv6) ipv6=1 ;; + -b|--both) ipv4=1; ipv6=1 ;; + *) echo "Unknown parameter passed: $1" ;; + esac + shift +done + +if [ $ipv4 -eq 1 ] && [ $ipv6 -eq 1 ]; then + ip a | grep inet | awk '{print $2}' | sed -e /^fe80::/d | awk -F/ '{print $1}' +elif [ $ipv4 -eq 1 ] ; then + ip a | grep 'inet ' | awk '{print $2}' | awk -F/ '{print $1}' +elif [ $ipv6 -eq 1 ] ; then + ip a | grep 'inet6 ' | awk '{print $2}' | sed -e /^fe80::/d | awk -F/ '{print $1}' +else + echo "Usage:" + echo "-4|--ipv4 list only IPv4 addresses" + echo "-6|--ipv6 list only IPv6 addresses" + echo "--both list both IP4 and IPv6 addresses" + echo "" + exit 1 +fi |