Last active
May 7, 2019 02:31
-
-
Save o0-o/cbcd637649edd2928b4483223b042abb to your computer and use it in GitHub Desktop.
[IPv4 Addresses] Prints IPv4 addresses of the host #Shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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