PublicSoftTools

IP Geolocation API — Free IP Location Lookup

Look up any IP address and get city, country, ISP, coordinates, and timezone as a clean JSON response. Includes a live API endpoint and integration examples in JavaScript, Python, cURL, and PHP. No signup required.

⏱ 6 min read · Complete guide below

GEThttps://www.publicsofttools.com/api/ip-geolocation
Integration Examples
const res = await fetch('https://www.publicsofttools.com/api/ip-geolocation');
const data = await res.json();
// data.ip, data.city, data.country, data.isp …
console.log(data);

How the IP Geolocation API Works

  1. 1Enter any IPv4 or IPv6 address in the input field, or click My IP to look up your own public IP automatically.
  2. 2Click Lookup. The request goes to /api/ip-geolocation, which queries the ip-api.com geolocation database and returns a normalised JSON response.
  3. 3The summary cards show the key fields at a glance: location, ISP, coordinates, timezone, and ASN. The JSON panel shows the complete response you would receive when calling the endpoint from code.
  4. 4Copy the API endpoint URL and paste it into your project. Switch between the JavaScript, Python, cURL, and PHP tabs to get ready-to-use code snippets for your language.

API Response Format

Every successful response is a flat JSON object with consistent field names. Fields that have no data for a given IP are returned as null rather than being omitted, so your code can always destructure the same shape. The three boolean flags — isMobile, isProxy, and isHosting — default to false when the information is unavailable.

Error responses follow the same structure: a JSON object with an error string field and an appropriate HTTP status code (400 for invalid input, 404 for unresolvable IPs, 502 for upstream service failures).

What Developers Use IP Geolocation For

IP geolocation shows up in a surprising number of everyday product features. The most common is content localisation — pre-selecting a country in a dropdown, defaulting a currency or language, or showing region-appropriate pricing so a first-time visitor sees something sensible before they set any preferences. It also powers routing decisions, such as sending a user to the nearest server, CDN edge, or regional data centre to cut latency. On the security side, geolocation feeds fraud and abuse checks: flagging a login from an unexpected country, applying stricter rules to traffic from hosting ranges, or blocking regions a service does not operate in. And in analytics, mapping visitor IPs to countries and cities gives a geographic picture of an audience without asking anyone to share their location. The boolean flags this API returns — isProxy, isHosting, and isMobile — are often as valuable as the coordinates for these jobs, because they describe the nature of a connection, not just its place.

Accuracy, Privacy, and the Right Way to Use It

Two principles keep an IP-geolocation feature both useful and responsible. First, respect its accuracy limits: treat the result as an approximate, city-level hint, never as a precise or verified location. Build every feature so it degrades gracefully when the data is wrong or missing — offer an easy way to change the auto-selected country, and never make an irreversible decision purely on a geolocated guess. Second, mind the privacy dimension. In some jurisdictions an IP address is considered personal data under laws like the GDPR, so if you store geolocation results tie them to a clear purpose, retain them only as long as you need, and disclose the practice in your privacy policy. Combined with aggressive caching — IP-to-location mappings rarely change more than once every few weeks — these habits give you a fast, low-cost feature that stays on the right side of both accuracy and compliance.

Tips for Using IP Geolocation in Applications

Cache results aggressively

IP-to-location mappings rarely change more than once every few weeks. Cache geolocation results by IP address with a TTL of 24–48 hours to avoid repeated API calls for the same address and stay well within rate limits.

Never use for precise location

IP geolocation is not a substitute for GPS or explicit user location consent. City-level accuracy is typical but not guaranteed. Use it for soft defaults (pre-filling a country selector, routing to the nearest server) — not for anything requiring precise geography.

Check isProxy before trusting the location

If isProxy is true, the IP belongs to a VPN, proxy, or Tor exit node. The reported location is the proxy server's location, not the user's actual location. Factor this into any geo-based logic in your application.

Handle null fields gracefully

Not every IP resolves to a city or region. Always provide a fallback in your UI — show "Unknown" or skip the field rather than displaying "null" to users. Country-level data is available for most IPs even when city data is missing.

Use isHosting to detect data centre IPs

When isHosting is true, the IP belongs to a cloud provider, CDN, or data centre. This is useful for distinguishing real user traffic from bot or automated traffic in analytics and rate-limiting systems.

Pair with WHOIS for more detail

Geolocation tells you where an IP is physically located. WHOIS tells you who owns the IP block (the network operator or organisation). For security investigations, combine both: geolocation narrows the geography, WHOIS confirms the registrant.

Frequently Asked Questions

What data does the IP Geolocation API return?

Each response includes: IP address, city, region, region code, country name, country code, zip/postal code, latitude, longitude, timezone, ISP, organisation name, ASN, and three boolean flags — isMobile, isProxy, and isHosting. All fields are returned as a flat JSON object.

How do I call the API endpoint from my own code?

Send a GET request to https://www.publicsofttools.com/api/ip-geolocation?ip=8.8.8.8 — replacing 8.8.8.8 with any valid IPv4 or IPv6 address. Omit the ip parameter entirely to return geolocation data for the requesting IP address. The API returns JSON with Content-Type: application/json.

What does the "My IP" button do?

Clicking "My IP" sends a lookup request with no IP parameter. The server reads the IP address from the incoming HTTP request headers (x-forwarded-for or x-real-ip) and returns geolocation data for that address — your public IP as seen from the internet.

How accurate is the location data?

City-level accuracy is typically within 50–100 km for most IPs. Country-level accuracy is very high (over 99% for IPv4). Mobile carriers and VPN providers often report different regions from the user's physical location. Corporate IPs typically resolve to the organisation's headquarters or data centre, not individual users.

Why do some IPs return no city or region?

Not every IP has a precise location mapped in the geolocation database. Reserved address ranges, newly allocated IP blocks, and some corporate networks may return country-level data only, or no location data at all. Private ranges (10.x.x.x, 192.168.x.x, 172.16–31.x.x) are not routable on the public internet and will return an error.

What is the rate limit?

The underlying geolocation data comes from ip-api.com, which allows up to 45 requests per minute on the free tier. For production applications making higher volumes of requests, you should obtain your own API key from ip-api.com or a similar provider and call their service directly rather than routing through this tool.

Does the API support IPv6?

Yes. Pass any valid IPv6 address as the ip parameter. Geolocation coverage for IPv6 is less complete than for IPv4, so some IPv6 addresses may return fewer location fields.

Is this suitable for production use?

This tool is designed for development, testing, and learning — verifying integration code, exploring the API response format, and checking IP data for debugging. For production applications with high traffic, call a geolocation API provider directly with your own account and API key to ensure SLA guarantees, higher rate limits, and stable terms of service.