Skip to content

Instantly share code, notes, and snippets.

@YourFriendCaspian
Forked from wozoopa/showips
Created September 2, 2017 04:07
Show Gist options
  • Save YourFriendCaspian/3c73993bef5975bfe50bc972cf8e4ba0 to your computer and use it in GitHub Desktop.
Save YourFriendCaspian/3c73993bef5975bfe50bc972cf8e4ba0 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