add option -i for ips to display interface(s)
parent
4590042177
commit
9ed26fac3f
|
|
@ -4,13 +4,24 @@ about-plugin 'miscellaneous tools'
|
||||||
function ips ()
|
function ips ()
|
||||||
{
|
{
|
||||||
about 'display all ip addresses for this host'
|
about 'display all ip addresses for this host'
|
||||||
|
param 'optional -i'
|
||||||
|
example '$ ips'
|
||||||
|
example '$ ips -i'
|
||||||
group 'base'
|
group 'base'
|
||||||
if command -v ifconfig &>/dev/null
|
if command -v ifconfig &>/dev/null
|
||||||
then
|
then
|
||||||
|
if [ -n "$1" -a "$1" = "-i" ];then
|
||||||
|
ifconfig | grep -B 1 -E "inet "| sed 's/addr://g' | sed 's/: / /g' | awk '{if (NR%3==1) print $1 ":"; else if (NR%3==2) print $2}'
|
||||||
|
else
|
||||||
ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }'
|
ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }'
|
||||||
|
fi
|
||||||
elif command -v ip &>/dev/null
|
elif command -v ip &>/dev/null
|
||||||
then
|
then
|
||||||
|
if [ -n "$1" -a "$1" = "-i" ];then
|
||||||
|
ip addr | grep -E '^\s*[1-9]| (25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{1,2})' | awk '{print $2}'
|
||||||
|
else
|
||||||
ip addr | grep -oP 'inet \K[\d.]+'
|
ip addr | grep -oP 'inet \K[\d.]+'
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "You don't have ifconfig or ip command installed!"
|
echo "You don't have ifconfig or ip command installed!"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue