Skip to content

Instantly share code, notes, and snippets.

@likejazz
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save likejazz/c682606a3a98049a7b25 to your computer and use it in GitHub Desktop.
Save likejazz/c682606a3a98049a7b25 to your computer and use it in GitHub Desktop.
PLATFORM=`uname`
if [[ "$PLATFORM" == 'Darwin' ]]; then # Mac
IP=`/sbin/ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}'`
elif [[ "$PLATFORM" == 'Linux' ]]; then # Linux
IP=`/sbin/ifconfig eth0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*'`
fi
print $IP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment