How to find your public IP from the command line

Finding your public IP (a.k.a external IP address) can become a common task. You may want to test that your proxy settings are working correctly, to find the location of a proxy server or temporally expose you service to the outside world.

Whatever the reason, there are several sites that you can accomplish the task. However, you can do easily command line with the help of the API from The API is simple API which allow you to find the public IP, the region, city, country and the timezone. Moreover, It supports up to 1000 requests per day without signup and has very comparative prices, in the case more calls is needed.

Finding your public IP

Finding you public IP or external IP is simple. Just invoke the following command :

Find your public IP
 ~/# curl

Finding your public IP full data

You can also find all the IP data in JSON format :

Find your public IP data
 ~/# curl
   "ip": "",
   "city": "London",
   "region": "England",
   "region_code": "ENG",
   "country": "GB",
   "country_name": "United Kingdom",
   "continent_code": "EU",
   "postal": "EC2V",
   "latitude": 51.5142,
   "longitude": -0.0931,
   "timezone": "Europe/London",
   "utc_offset": "+0000",
   "country_calling_code": "+44",
   "currency": "GBP",
   "languages": "en-GB,cy-GB,gd",
   "asn": "AS14061",
   "org": "DigitalOcean, LLC"

You can also find specific field value of the above IP data

Find your public IP
 ~/# curl
{%code { "lang":"bash" , "title":"Find your location - country. city, region and timezone" } %} ~/# curl GB ~/# curl London ~/# curl England ~/# curl Europe/London ~/# curl +0000

Finding proxy server location

The curl -x allows to fetch a page via proxy. We can use it find the IP data of the proxy server. Suppose you want to find the location of your proxy server my-proxy at port 8085:

Find proxy server location - country,city and timezone
 ~/# curl -x http://my-proxy:8085
 ~/# curl -x http://my-proxy:8085
 ~/# curl -x http://my-proxy:8085
 ~/# curl -x http://my-proxy:8085
 ~/# curl -x http://my-proxy:8085

For web developers

If you web developer you can use the API to display customized content of your website based on the location of the IP. For example, you can display the relevant flag or currency. Another example, you can display relevant locations and events based on the visitor's country or city.

Suppose you want to find data of the machine (Google Public DNS) :

Find IP data of specific IP
 ~/# curl
     "ip": "",
     "city": "Mountain View",
     "region": "California",
     "region_code": "CA",
     "country": "US",
     "country_name": "United States",
     "continent_code": "NA",
     "postal": "94035",
     "latitude": 37.386,
     "longitude": -122.0838,
     "timezone": "America/Los_Angeles",
     "utc_offset": "-0800",
     "country_calling_code": "+1",
     "currency": "USD",
     "languages": "en-US,es-US,haw,fr",
     "asn": "AS15169",
     "org": "Google LLC"