Skip to content

Instantly share code, notes, and snippets.

@o0-o
Last active May 7, 2019 02:31
Show Gist options
  • Save o0-o/cbcd637649edd2928b4483223b042abb to your computer and use it in GitHub Desktop.
Save o0-o/cbcd637649edd2928b4483223b042abb to your computer and use it in GitHub Desktop.
[IPv4 Addresses] Prints IPv4 addresses of the host #Shell
# net_ip4.sh
( # linux (NetworkManager)
nmcli -terse -mode tabular -fields IP4.ADDRESS device show ||
# linux (iproute2)
ip -family inet -brief address |
# linux/bsd
( ip address || ifconfig ) |
grep "inet " |
sed 's/cast.*//g'
) 2>/dev/null |
grep --only-matching --extended-regexp --regexp="([0-9]{1,3}\.){3}[0-9]{1,3}" |
grep --invert-match "^127" ||
exit 1 #failure
exit 0 #success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment