Thursday, June 16, 2022

Getting IP Geolocation Information Using Curl

The tool that we are going to use is just curl. We need to access the url of the website that will provide the geolocation information of the IP address. Let's get to it.

The first provider, is by using ipapi.co. To get the geolocation of an ip from ipapi.co:
$ curl https://ipapi.co/ip-address/json

For example, to get the geolocation information of google dns, we can type:
$ curl https://ipapi.co/8.8.8.8/json

And we should be getting some output like this:
{
    "ip": "8.8.8.8",
    "network": "8.8.8.0/24",
    "version": "IPv4",
    "city": "Mountain View",
    "region": "California",
    "region_code": "CA",
    "country": "US",
    "country_name": "United States",
    "country_code": "US",
    "country_code_iso3": "USA",
    "country_capital": "Washington",
    "country_tld": ".us",
    "continent_code": "NA",
    "in_eu": false,
    "postal": "94043",
    "latitude": 37.42301,
    "longitude": -122.083352,
    "timezone": "America/Los_Angeles",
    "utc_offset": "-0800",
    "country_calling_code": "+1",
    "currency": "USD",
    "currency_name": "Dollar",
    "languages": "en-US,es-US,haw,fr",
    "country_area": 9629091.0,
    "country_population": 327167434,
    "asn": "AS15169",
    "org": "GOOGLE"
}

We can also specify which information we want to be displayed specifically:
$ curl https://ipapi.co/8.8.8.8/country
US

The second provider is ipinfo.io. Similar to the above example, we can just use curl like below to get the geolocation information of a certain ip address:
$ curl https://ipinfo.io/ip-address

For example, to get the information of the ip 8.8.8.8, we can issue this command:
$ curl https://ipinfo.io/8.8.8.8

and we should get output like this
{
  "ip": "8.8.8.8",
  "hostname": "dns.google",
  "anycast": true,
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.4056,-122.0775",
  "org": "AS15169 Google LLC",
  "postal": "94043",
  "timezone": "America/Los_Angeles",
  "readme": "https://ipinfo.io/missingauth"

Like the above example, we can also specify what information we wan to be shown, by using:
$ curl https://ipinfo.io/8.8.8.8/postal

And we should get something like this:
94043

No comments:

Post a Comment