Free JSON Geolocation API

Cloudflare has free geolocation on

https://radar.cloudflare.com/ip

or direct json file

https://ipv4-check-perf.radar.cloudflare.com/api/info

{
  "colo": "CGK",
  "asn": 123,
  "continent": "AS",
  "country": "ID",
  "region": "Jakarta",
  "city": "Bandung",
  "ip_address": "123.xxx.xxx.xxx",
  "ip_version": "IPv4"
}

but both only work in browser and not using curl/wget.

so can you create free json endpoint that can be used by curl/wget without “CF Check”

1 Like

You can simulate user-agent in this case Postman (just cos it’s shorter than the browser agent description).
Run this two times. The first time a cookie will be stored on disk and the second time that cookie will be used and you should get the json you wanted. I’m not sure if it applies to your use case. Maybe somehow store the cookie in a variable (I haven’t figured that out yet).
curl --cookie cookie.txt --cookie-jar cookie.txt --location 'https://ipv4-check-perf.radar.cloudflare.com/api/info' --user-agent 'PostmanRuntime/7.37.0'

1 Like

yes I can, but we need more simple solution like

curl ip.cloudflare.com

Maybe you can sport yourself a Cloudflare Worker in minutes. You are provided with an URL to the worker and you can Curl directly to it.

export default {
  async fetch(request) {
    let ip = "not available";
    let ipHeader = "CF-Connecting-IP"
    if (request.headers.has(ipHeader)){
      ip=request.headers.get(ipHeader)
    };
    const data = {
      ip: ip,
      Colo: request.cf.colo,
      Country: request.cf.country,
      City: request.cf.city,
      Continent: request.cf.continent,
      Latitude: request.cf.latitude,
      Longitude: request.cf.longitude,
      PostalCode: request.cf.postalCode,
      MetroCode: request.cf.metroCode,
      Region: request.cf.region,
      RegionCode: request.cf.regionCode,
      Timezone: request.cf.timezone,
    };
    return Response.json(data);
  },
};
1 Like

Thanks I will use that solution for now.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.