Locate an IP address and identify its network

Country, region and timezone from an IP address, the network that owns it, and an honest account of where that data turns into a guess.

Every request that reaches your server carries one fact the client did not choose to tell you: the address it came from. It is the cheapest fraud signal you have, because you already hold it, and the most misused, because it looks far more precise than it is.

This lesson gets you two things from an IP address. The first is a location: a country you can mostly trust, a region and timezone you can use as defaults, and a city you should treat as a rumour. The second is the network behind it, the Autonomous System that announces the address to the rest of the internet, which tells you whether you are talking to a home broadband line, a mobile carrier or a rented server. The next three lessons build on both.

What an IP address can tell you

An IP address is a routing label, not an identity. It says which network will deliver packets to the client, and the geolocation databases behind every IP API are educated reconstructions of where those networks put their customers. They are built from registry records, ISP feeds, latency measurements and corrections people submit. Some of that is very good. None of it is a GPS fix.

Three properties follow from that, and they shape every decision in this course:

  • Coarse is reliable, fine is not. Country is right for the vast majority of residential and mobile addresses. Region is usually right. City is often the location of the ISP's equipment, or the nearest big town, or the centre of the country when the database has nothing better.
  • The address is not the person. Behind one IP there may be a family, a coffee shop, an office of 2,000, or a mobile carrier sharing one public address across thousands of phones (carrier-grade NAT). Behind one person there may be dozens of IPs over a week.
  • The address can be borrowed. VPNs, proxies, Tor and cloud servers let anyone appear wherever they like. Detecting that is lesson 2. In this lesson, assume the address is honest and learn what it says.

Look up an IP

IP Lookup (iplookup) takes one ip query parameter on a GET and costs 10 credits. Try it on the example address from its definition:

Try it liveIP Lookup10 credits
GEThttps://api.apiverve.com/v1/iplookup
curl "https://api.apiverve.com/v1/iplookup?ip=173.172.81.20" \
  -H "x-api-key: YOUR_API_KEY"
Sign in or create a free account to run this with your own key.

country, region and timezone are on every plan; city, coordinates and accuracyRadius are premium.

The response splits cleanly into fields every plan gets and fields that need a higher plan:

FieldPlanWhat it is good for
country, countryNameallISO 3166-1 alpha-2 code and name. Defaults, compliance routing, mismatch checks
region, regionNameallState or province. Tax defaults, regional content
timezoneallIANA zone such as America/Chicago. Scheduling defaults, "local time" checks
continent, continentNameallCoarse routing, analytics
city, postalCode, coordinatespremiumDisplay only, never decisions
accuracyRadiuspremiumHow far, in kilometres, the true location may be from coordinates
isEUpremiumEU membership of the country
asn, asnNamepremiumThe network announcing the address

Write your code so the premium fields are optional from the first line. A field that is missing on one plan and present on another should never be the difference between your code working and throwing.

region deserves a note too: for some addresses it is null even on paid plans, because the database only knows the country. The lookup for Google's public resolver 8.8.8.8 returns country: "US", a null region and city, and an accuracyRadius of 1000 km.

How accurate is it, really?

Two observations from real calls make the point better than any disclaimer.

First, the same address moves. The sample response stored in the catalog for 173.172.81.20 places it in Kansas City, Missouri. A call made the day this lesson was written placed it in Lincoln, Nebraska, roughly 300 km away, while still reporting a 20 km accuracy radius. Both answers came from the same API. ISPs reassign address blocks between regions and the databases catch up later; the radius describes the database's confidence, not a guarantee.

Second, "no idea" looks like a location. When the database knows only the country, it still returns coordinates: for many US addresses those are [37.751, -97.822], a point in rural Kansas near the geographic centre of the country, paired with an accuracy radius of 1000 km. Put that on a map without reading the radius and you will tell a user in Boston that they are in a wheat field.

So the rules:

  • Decide on country, use region and timezone as defaults the user can change, and use city only for display ("Signed in near Lincoln, NE") with words that admit uncertainty.
  • If you show coordinates, draw a circle of accuracyRadius, not a pin, and hide it entirely when the radius is in the hundreds of kilometres.
  • Never use IP location as proof of residence for anything with legal weight. It is a hint you corroborate with a billing address, a phone number or a document.
Check yourself

An IP lookup returns coordinates [37.751, -97.822] with accuracyRadius 1000. What should a login-history screen show?

Answer the check above to continue.

Run every example on your own key. Free plan, no card.

Scaling up?

Volume pricing, custom SLAs, and dedicated support for high-traffic teams.

Contact sales