Skip to content

Instantly share code, notes, and snippets.

@wozoopa
Created September 1, 2014 02:12
Show Gist options
  • Save wozoopa/83892b5e9c5ff41f9fc1 to your computer and use it in GitHub Desktop.
Save wozoopa/83892b5e9c5ff41f9fc1 to your computer and use it in GitHub Desktop.
Get ip addresses for each interface in linux with bash function.
showips() {
NAMES=( $($IFC | grep "lo\|eth\|wlan" -A 1 | awk -F" " '{print $1 }' | grep -v "inet\|-\|UP" | 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment