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 ipapi.co. The ipapi.co 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 https://ipapi.co/ip
138.68.1.1

Finding your public IP full data

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

Find your public IP data
~/# curl https://ipapi.co/json
{
  "ip": "138.68.1.1",
  "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 https://ipapi.co/ip
138.68.1.1
Find your location - country. city, region and timezone
~/# curl https://ipapi.co/country
GB
~/# curl https://ipapi.co/city
London
~/# curl https://ipapi.co/region
England
~/# curl https://ipapi.co/timezone
Europe/London
~/# curl https://ipapi.co/utc_offset
+0000

Finding proxy server location

The curl -x <proxy> 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 https://ipapi.co/country
FR
~/# curl -x http://my-proxy:8085 https://ipapi.co/city
Vélizy-Villacoublay
~/# curl -x http://my-proxy:8085 https://ipapi.co/region
Île-de-France
~/# curl -x http://my-proxy:8085 https://ipapi.co/timezone
Europe/Paris
~/# curl -x http://my-proxy:8085 https://ipapi.co/utc_offset
+0100

For web developers

If you web developer you can use the ipapi.co 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 8.8.8.8 (Google Public DNS) :

Find IP data of specific IP
~/# curl https://ipapi.co/8.8.8.8/json
{
    "ip": "8.8.8.8",
    "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"
}