-
-
Save forestbaker/82e15604ff619dd4f277 to your computer and use it in GitHub Desktop.
Get ip addresses for each interface in linux with bash function.
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
declare -rx IFC='/sbin/ifconfig' | |
showips() { | |
NAMES=( $($IFC | egrep 'lo|eth|wlan|en' -A 1 | awk -F' ' '{print $1 }' | egrep -v 'inet|-|UP|RX|collisions' | sort -u) ) | |
for i in "${NAMES[@]}"; do | |
echo "$i has ip address: $($IFC | grep $i -A 1 | grep 'addr' | awk -F' ' '{print $2}' | awk -F':' '{print $2}')" | |
done | |
} | |
# alternative to above | |
# hmm ... more testing ... | |
for i in {0..9}; do | |
ip addr list eth${i} | grep 'inet ' | tr -s ' ' | cut -d ' ' -f 3 | cut -d '/' -f 1) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment