IP Address Bash Script for OS X
As a developer, I often need to get my external IP address and while there are numerous widgets, websites and apps for this, I wanted a nice, quick bash script to do it. I’ve adapted the script from a few internet sources (including a message on Ars Technica) and modified & enhanced it for my own uses. Put this in your .profile and you’ll then be able to type “ip” to get all the internal/external IP addresses. The external IP will then get copied to your paste board.
You can download the script here in text format.
function ip() {
local ETHERNET=`ipconfig getifaddr en0 2> /dev/null`
local WIFI=`ipconfig getifaddr en1 2> /dev/null`
local EXT=`curl -s http://checkip.dyndns.org/ | grep -o '[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9]*'`
if [ "$ETHERNET" != "" ]; then
echo -n -e "Ethernet:\t "
echo -e $ETHERNET
fi
if [ "$WIFI" != "" ]; then
echo -n -e "WiFi:\t\t "
echo -e $WIFI
fi
echo -n -e "External:\t "
echo -e $EXT
echo -e $EXT | pbcopy
echo ""
}