Last Updated: February 25, 2016
·
754
· tbasse

Get IPs of your Network Interfaces plus your External Address

This goes into your bash config:

ip() {
  INTERFACE=`ifconfig -l`
  for IT in $INTERFACE
  do
    IP=`ifconfig "$IT" | grep 'inet ' | awk '{print $2}'`
    if [[ $IP ]]; then
      echo $IT $IP
    fi
  done
  echo "ext" `dig +short myip.opendns.com @resolver1.opendns.com`
}

Now you just type ip and get a list like this:

lo0 127.0.0.1
en0 192.168.0.31
en1 192.168.0.32
ext 17.35.192.29

1 Response
Add your response

grep is not needed for this:

grep 'inet ' | awk '{print $2}'`

This can be done in awk

awk '/inet/ {print $2}'`
over 1 year ago ·