IPv4 lookup
Location, timezone and network details for an IPv4 address. Leave the address out to look up the caller.
GEThttps://api.mygeocode.com/v1/ipv4
Parameters
| Parameter | Type | Description |
|---|---|---|
ipoptional | string | Dotted IPv4 address. Default: the address the request came from. |
ipsoptional | string | Comma-separated addresses, up to 100, for a batch. Returns results array in the same order. Each counts as one request. |
langoptional | string | ISO 639-1 code for country, region and city names. Default en. |
keyoptional | string | API key, if not sent as a header. |
Example
$ curl "https://api.mygeocode.com/v1/ipv4?ip=1.1.1.1"// In a browser, with no ip parameter, this returns the visitor's own address
const geo = await (await fetch("https://api.mygeocode.com/v1/ipv4")).json();
console.log(geo.country_code, geo.timezone);import requests
geo = requests.get("https://api.mygeocode.com/v1/ipv4", params={"ip": "1.1.1.1"}, timeout=5).json()
print(geo["country_code"], geo["org"], geo["is_datacenter"])Response
{
"status": "ok",
"ip": "1.1.1.1",
"version": 4,
"country": "Australia",
"country_code": "AU",
"region": "Queensland",
"region_code": "QLD",
"city": "Brisbane",
"postcode": "4000",
"lat": -27.4679,
"lon": 153.0281,
"timezone": "Australia/Brisbane",
"asn": 13335,
"org": "Cloudflare, Inc.",
"is_datacenter": true,
"is_proxy": false,
"is_private": false
}Response fields
| Field | Type | Description |
|---|---|---|
ip | string | The address looked up. |
version | integer | Always 4 on this endpoint. |
country, country_code | string | Name in lang, and the upper-case ISO 3166-1 alpha-2 code. |
region, region_code | string | First-level division and its ISO 3166-2 suffix. Absent if unknown. |
city, postcode | string | Best estimate. Absent if unknown. |
lat, lon | number | Centre of the most specific known area. |
timezone | string | IANA name. |
asn, org | integer, string | Autonomous system number and the announcing organisation. |
is_datacenter | boolean | Hosting or cloud range. |
is_proxy | boolean | Known VPN, Tor or public proxy exit. |
is_private | boolean | RFC 1918, loopback, link-local or otherwise not publicly routed. When true, the location fields are absent. |
Notes
- Anycast addresses such as
1.1.1.1and8.8.8.8are served from many places at once. The location returned is the registered one, which is whyis_datacenteris true for them. - When calling without
ipthrough a proxy or CDN, the address seen is the proxy's. Pass the real client address inipfrom your server instead. - IP data is refreshed weekly. A cache time of a day is reasonable.
The same lookup in other providers' formats
If you already have code written against one of these providers, keep it: the drop-in host accepts the same path and parameters and answers in that provider's response shape, with this endpoint behind it. See how the drop-ins work.
| Provider | Host | Path |
|---|---|---|
| Geoapify | geoapify.mygeocode.com | /v1/ipinfo?ip=... |
| ip-api.com | ipapi.mygeocode.com | /json/{ip}/json//batch (POST, JSON array) |
| ipinfo.io | ipinfo.mygeocode.com | /{ip}/json/{ip}/json/{ip}/{field} |
| ipstack | ipstack.mygeocode.com | /{ip}/check/{ip},{ip},{ip} |
Errors
400 invalid_request when ip is not a valid IPv4 address, or when an IPv6 address is sent to this endpoint (use /v1/ipv6), or when ips has more than 100 entries.