IP Geolocation and User Agent Parsing in One API Key
Published: · APIs in this article: IP Geolocation, User Agent Parser, IP Intelligence (Cloud, Tor, Bots)
Every HTTP request carries two clues about who sent it: the client IP and the User-Agent header. Turned into data, they answer useful questions. Which country should the checkout form pre-select? Is this sign-up coming from a data centre? Was that spike in "visits" real people or link-preview crawlers? Which browser was the customer using when the bug happened?
This guide shows how to get those answers with three APIBox endpoints that share one API key:
/v1/ip– country, region, city, coordinates, ASN and organisation for an IP./v1/user-agent– browser, engine, OS, device and a bot flag from a User-Agent string./v1/ip-intel– whether an IP is cloud hosting, a Tor exit node, or a verified crawler.
Setup
Create a free APIBox account and an API key. The Free plan has 1,000 requests a month and no card is needed.
export APIBOX_KEY="your_key"1. Geolocate an IP
curl -s https://apibox.io.vn/v1/ip/8.8.8.8 \
-H "Authorization: Bearer $APIBOX_KEY"/v1/ip?ip=8.8.8.8 works too.
{
"ip": "8.8.8.8",
"version": 4,
"country_code": "US",
"country": "United States",
"flag": "🇺🇸",
"is_eu": false,
"calling_code": "+1",
"continent": "North America",
"region": "California",
"city": "Mountain View",
"latitude": 37.422,
"longitude": -122.085,
"asn": 15169,
"organization": "Google LLC",
"source": "db-ip.com lite",
"database_version": "2026-11",
"attribution": "IP Geolocation by DB-IP",
"attribution_url": "https://db-ip.com"
}A few things to know about the data:
- Arbitrary IPs are looked up in the DB-IP Lite database (CC BY 4.0), refreshed monthly. Results are cached for 24 hours. Where you display the data, show the credit from
attributionas a link toattribution_url:<a href="https://db-ip.com">IP Geolocation by DB-IP</a>. - Country and ASN are reliable. City and coordinates are approximate. They often point to the ISP's hub, and VPNs or mobile carriers can place users far from where they are. Use the city for "probably", never for anything legal or billing-critical.
- IPv4 and IPv6 are both supported, including IPv4-mapped IPv6 like
::ffff:8.8.8.8. That one returns the same Google record as8.8.8.8, withversion: 4. - Private, loopback and other reserved addresses come back with
reserved: trueand the range name instead of a location. Handy when your logs contain10.xaddresses from an internal proxy./v1/ip/10.0.0.5returns just:
{ "ip": "10.0.0.5", "version": 4, "reserved": true, "range": "private" }"What is my IP?"
Call /v1/ip with no IP and the API describes the caller's own address using Cloudflare's edge data ("source": "cloudflare"). That response also has region_code, postal_code (can be null) and timezone (for example Asia/Ho_Chi_Minh). Remember it's the address of whoever made the call. If your server calls it, you get your server's IP, not your visitor's. For visitors, read the client IP on your server (for example from CF-Connecting-IP or X-Forwarded-For behind a trusted proxy) and pass it explicitly.
2. Parse a User-Agent
curl -s -G https://apibox.io.vn/v1/user-agent \
-H "Authorization: Bearer $APIBOX_KEY" \
--data-urlencode "ua=Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1"{
"ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1",
"browser": { "name": "Mobile Safari", "version": "17.5", "major": "17" },
"engine": { "name": "WebKit", "version": "605.1.15" },
"os": { "name": "iOS", "version": "17.5" },
"device": { "type": "mobile", "vendor": "Apple", "model": "iPhone" },
"cpu": null,
"is_bot": false,
"is_mobile": true,
"is_tablet": false,
"is_desktop": false
}Parsing is based on the open-source ua-parser-js library. The booleans (is_mobile, is_tablet, is_desktop, is_bot) save you from writing your own rules.
is_bot matches common crawlers, link-preview fetchers and HTTP clients: Googlebot, Bingbot, facebookexternalhit, Slack, Discord, Telegram and WhatsApp previews, curl, wget, python-requests, axios, headless browsers, Lighthouse and uptime monitors. It is pattern based. A bot that sends a normal browser User-Agent won't be flagged. That's what section 4 is for.
Omit ua and the API parses the User-Agent of the request itself. Call it bare from a terminal and you'll see how a non-browser client looks: for curl/8.18.0 every browser and OS field is null, device.type is "bot" and is_bot is true.
3. Enrich a sign-up on the server (JavaScript)
Here's a typical pattern: when a user signs up, look up both values in parallel and store a compact summary next to the account.
const KEY = process.env.APIBOX_KEY;
const H = { Authorization: `Bearer ${KEY}` };
const API = 'https://apibox.io.vn/v1';
export async function requestContext(ip, ua) {
const [geo, agent] = await Promise.all([
fetch(`${API}/ip/${encodeURIComponent(ip)}`, { headers: H }).then((r) => (r.ok ? r.json() : null)),
fetch(`${API}/user-agent?ua=${encodeURIComponent(ua)}`, { headers: H }).then((r) => (r.ok ? r.json() : null)),
]);
return {
country: geo?.country_code ?? null,
asn: geo?.asn ?? null,
org: geo?.organization ?? null,
browser: agent?.browser?.name ?? null,
os: agent?.os?.name ?? null,
device: agent?.device?.type ?? null,
is_bot: agent?.is_bot ?? null,
};
}
// requestContext('8.8.8.8', '<a Chrome 131 on Windows UA>') returns:
// { country: 'US', asn: 15169, org: 'Google LLC',
// browser: 'Chrome', os: 'Windows', device: 'desktop', is_bot: false }
// Express example: behind a trusted proxy, req.ip is the client address
// app.post('/signup', async (req, res) => {
// const ctx = await requestContext(req.ip, req.get('user-agent') || '');
// ...
// });Two habits worth keeping:
- Fail open. If a lookup fails or you're out of quota, the helper returns
nullfields instead of blocking the sign-up. - Cache by IP. The same IP often signs in many times a day. A short cache on your side (an hour or so) saves requests. The API already caches arbitrary-IP lookups for 24 hours on its side.
Each call is one request, so this pattern costs two requests per sign-up.
4. Catch fake crawlers with /v1/ip-intel
Anyone can send User-Agent: Googlebot. Search engines publish the IP ranges their crawlers use, and the way to verify a crawler is to check the IP against those ranges. /v1/ip-intel does that, plus cloud and Tor checks:
curl -s -G https://apibox.io.vn/v1/ip-intel \
-H "Authorization: Bearer $APIBOX_KEY" \
--data-urlencode "ip=66.249.66.1" \
--data-urlencode "ua=Mozilla/5.0 (compatible; Googlebot/2.1)"{
"ip": "66.249.66.1",
"valid": true,
"version": 4,
"is_cloud": false,
"cloud": null,
"is_tor_exit": false,
"is_crawler": true,
"crawler": { "name": "Googlebot", "operator": "Google", "type": "crawler", "cidr": "66.249.66.0/27", "verified_by": "official IP ranges" },
"google_network": true,
"user_agent": { "claims": "Google crawler", "genuine": true },
"risk": { "level": "low", "reasons": ["Verified Googlebot (official IP ranges)"] },
"matches": [ "… (truncated: the matching ranges, 66.249.66.0/27 googlebot and 66.249.64.0/19 google)" ],
"data_version": "202611222211",
"built_at": "2026-11-22T22:12:00.151Z",
"note": "Classification from the providers' own published IP range files (refreshed daily). …"
}Now send the same Googlebot User-Agent from 8.8.8.8, which is a Google address but not a crawler address:
{
"ip": "8.8.8.8",
"is_crawler": false,
"google_network": true,
"user_agent": { "claims": "Google crawler", "genuine": false },
"risk": { "level": "high", "reasons": ["User-Agent claims Google crawler but the IP is not in its published ranges"] },
"…": "… (truncated)"
}If the UA claims to be a known crawler but the IP is outside that crawler's published ranges, user_agent.genuine is false and risk.level is high. built_at tells you how fresh the range data is. The endpoint also tells you when an IP belongs to AWS, Google Cloud, Azure, Oracle Cloud, Cloudflare, DigitalOcean, Akamai/Linode or Vultr, and whether it's a current Tor exit node. All of this comes from the providers' own published range files, refreshed daily.
Limits: commercial VPNs and residential proxies publish no ranges, so they aren't detected. A "not cloud" result doesn't mean "a real person at home".
Python: tag log lines in bulk
import os, requests
KEY = os.environ["APIBOX_KEY"]
H = {"Authorization": f"Bearer {KEY}"}
ips = ["66.249.66.1", "8.8.8.8", "1.1.1.1"]
r = requests.post("https://apibox.io.vn/v1/ip-intel", json={"ips": ips}, headers=H, timeout=30)
r.raise_for_status()
data = r.json()
for res in data["results"]:
tag = res["crawler"]["name"] if res["is_crawler"] else ("cloud" if res["is_cloud"] else "-")
print(res["ip"], tag, res["risk"]["level"])Output:
66.249.66.1 Googlebot low
8.8.8.8 - low
1.1.1.1 - lowThe batch response is {"count": 3, "results": [...], "data_version": ..., "built_at": ..., "note": ...}, one result per IP with the same fields as a single lookup. There's no user_agent block in batch results, since you don't send a UA per IP. /v1/ip-intel accepts up to 1,000 addresses per POST (20 if you add dns=true), and one POST counts as one request against your quota, however many IPs it carries.
Which endpoint for which job
| Question | Endpoint |
|---|---|
| Which country / ISP is this IP? | /v1/ip |
| Which browser, OS, device? Obvious bot? | /v1/user-agent |
| Is this IP a data centre, Tor, or a real Googlebot? | /v1/ip-intel |
FAQ
How accurate is IP geolocation? Country is right for the vast majority of addresses, and ASN comes from routing data. City and coordinates are approximate. VPNs and mobile networks can be off by hundreds of kilometres.
Can I call it from the browser? Don't: the call needs your API key. Do the lookup on your server, where you also see the real client IP.
Does it detect VPNs?
Only VPNs that run on the listed clouds show up as cloud traffic (/v1/ip-intel). Commercial VPN and residential proxy networks are not detected.
Is there a batch mode for /v1/ip?
/v1/ip takes one address per call. For many addresses at once, /v1/ip-intel accepts up to 1,000, but it classifies IPs (cloud, Tor, crawler) rather than geolocating them.
Get started
👉 Get a free API key – 1,000 requests a month, no card required.
Full parameters: IP Geolocation API · User Agent Parser API · IP Intelligence API.
More articles
- API Ninjas Holidays Alternative for Vietnam (+ Lunar)
Need Vietnam holidays beyond a date list? Compare API Ninjas Holidays with APIBox: Tết break, make-up days, 2027, lunar dates. Migration code included. - HTML to Markdown API: Clean Markdown From Any Web Page
Convert HTML or any URL to clean GitHub-flavored Markdown with one API call: tables, absolute links, Readability article extraction. curl, JS, Python. - OG Image Generator API: Social Cards From a Title
Generate 1200×630 Open Graph images from a title, subtitle and site name with one GET request. Themes, gradients, story and square sizes. curl + JS. - QR Code Generator API: PNG, SVG, WiFi and vCard
Generate QR codes as PNG or SVG with one GET request: URLs, WiFi logins, vCards, SMS. Custom colours, size and error correction. curl, JS, Python.