Notes

[curl] Get IP address (external) using URL endpoints

Edit on GitHub

Commands
2 minutes

external IP using dig

1dig +short myip.opendns.com @resolver1.opendns.com

This asks the IP address of myip.opendns.com from the name server resolver1.opendns.com (something you trust), which will return your external IP address.

curl works over HTTP, and therefore less efficient than the direct DNS query with dig.

external IP using curl

You can curl an endpoint for your external public IP, like so:

1curl http://ipecho.net/plain; echo

There are plenty of services that give you your public IP address by going to a URL. You can then curl that URL to see your external public IP in CLI.

Some alternatives are:

1curl https://icanhazip.com/
2curl http://ifconfig.me/ip
3curl http://ip.appspot.com/
4curl http://ip-addr.es/
5curl http://eth0.me/
6curl http://curlmyip.com/
7curl http://checkip.dyndns.org/
8curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+" # get onlt the IP digits

You can also get other details as well. For example:

1curl ifcfg.me/all

will give you your ISP and Country as well

curl ifcfg.me/all

Notes

  • icanhaz should be the most preferred since it works over SSL (https). It also seems to be well monitored for uptime.
  • ifcfg.me is better than ifconfig.me.
  • ifcfg.me has other interesting info as well: ISP, Country

icanhaz tools

  • icanhazip.com – returns your IP address
  • icanhazptr.com – returns the reverse DNS record (PTR) for your IP
  • icanhaztrace.com – returns a traceroute from my servers to your IP address
  • icanhaztraceroute.com – returns a traceroute from my servers to your IP address
  • icanhazepoch.com – returns the epoch time (also called Unix time)
  • icanhazproxy.com – can determine if your traffic is being proxied

Get JSON

1https://wtfismyip.com/json

OR

1curl https://wtfismyip.com/json