Skip to content

Instantly share code, notes, and snippets.

@mapix
Created August 10, 2012 05:54
Show Gist options
  • Save mapix/3311490 to your computer and use it in GitHub Desktop.
Save mapix/3311490 to your computer and use it in GitHub Desktop.
BASH: get current ip addr
OS=`uname`
IO="" # store IP
case $OS in
Linux) IP=`/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
FreeBSD|OpenBSD) IP=`/sbin/ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
SunOS) IP=`/sbin/ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
*) IP="Unknown";;
esac
echo "$IP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment