Updated WhatIsMyIP for Bash

A long time ago, I posted a snippet to get your IP address using Bash. Turns out the service I was using in that snippet has gone away, like so many others. Now to give you a few alternatives!

If you’ve got Python handy (you probably do), you can use my ip.coda.to service’s API to output way more information that just an IP address. curl ip.coda.to/api | python -m json.tool will give you quite a chunk of information! If you want to add that to your bash profile, use the snippet below.

ipinfo ()
{
  url="http://ip.coda.to/api"
  if [ "$1" ]; then
    url+="/$1"
  fi
  curl --location "$url" | python -m json.tool
}

If you just want an IP, there are a few good ways to get it. OpenDNS has a special DNS zone if you’re using their resolvers, so as long as you have a working nslookup (Windows, macOS, and most unixes with the bind-utils package).

nslookup myip.opendns.com 208.67.222.222

If you want to use curl, there’s a few options.

curl api.ipify.org
curl ifconfig.me/ip
curl wtfismyip.com/text
curl ipinfo.io/ip
curl whatismyip.akamai.com

 

AlexUpdated WhatIsMyIP for Bash