Skip to content

Instantly share code, notes, and snippets.

@elmundio87
Last active November 16, 2020 21:23
Show Gist options
  • Save elmundio87/4d560701ab8530ff4e47d591fe47ebea to your computer and use it in GitHub Desktop.
Save elmundio87/4d560701ab8530ff4e47d591fe47ebea to your computer and use it in GitHub Desktop.
A script to get the primary IP address on linux or mac
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
ip route get 1 | awk '{print $NF;exit}'
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
ipconfig getifaddr en0
else
# Unknown.
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment