IP Geolocation API: Complete Developer Guide
Build location-aware applications with IP geolocation data. Get country, city, ISP, timezone, and VPN detection from any IP address with under 25ms response time.
What Is IP Geolocation?
IP geolocation is the process of mapping an IP address to a physical location. Every device connected to the internet is assigned an IP address, and geolocation databases use this address to determine approximate geographic coordinates, ISP information, and connection metadata.
Unlike GPS, which provides pinpoint accuracy from a device sensor, IP geolocation estimates location based on internet infrastructure data. The accuracy depends on the IP type:
Residential IPs
95%+ city-level accuracy. Assigned by ISPs to home and mobile users.
Business IPs
90%+ city-level accuracy. Assigned to offices and enterprise networks.
Data Center / VPN IPs
Country-level only. Hosted by cloud providers or VPN services.
IP Geolocation Data Fields Explained
A comprehensive IP geolocation API returns multiple data fields. Here is what each field provides:
| Field | Description | Example |
|---|---|---|
| country | Country name and ISO code | United States (US) |
| region | State or province | California |
| city | City name | Mountain View |
| latitude/longitude | Geographic coordinates | 37.3861, -122.0839 |
| timezone | IANA timezone | America/Los_Angeles |
| isp | Internet Service Provider | Google LLC |
| asn | Autonomous System Number | AS15169 |
| vpn/proxy | VPN or proxy detection | false |
Getting Started with the Ops.Tools IP Geolocation API
Create Your Account
Sign up for an Ops.Tools account and navigate to your dashboard to generate an API key. Professional plans start at $29/month for 6,000 API calls.
Make Your First Request
Send a GET request to the IP geolocation endpoint. You can query any IPv4 or IPv6 address:
curl -X GET "https://api.ops.tools/v1/ip/geolocation?ip=8.8.8.8" \ -H "Authorization: Bearer YOUR_API_KEY"
Parse the Response
The API returns a JSON response with all geolocation data fields:
{
"ip": "8.8.8.8",
"country": "United States",
"countryCode": "US",
"region": "Virginia",
"city": "Ashburn",
"latitude": 39.03,
"longitude": -77.5,
"timezone": "America/New_York",
"isp": "Google LLC",
"asn": "AS15169",
"organization": "Google Public DNS",
"isVpn": false,
"isProxy": false,
"isDatacenter": true
}Code Examples in Popular Languages
Python
import requests
apiUrl = "https://api.ops.tools/v1/ip/geolocation"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
# Geolocate a specific IP
response = requests.get(apiUrl, headers=headers, params={"ip": "8.8.8.8"})
data = response.json()
print(f"Location: {data['city']}, {data['country']}")
print(f"ISP: {data['isp']}")
print(f"Timezone: {data['timezone']}")
print(f"VPN/Proxy: {data['isVpn'] or data['isProxy']}")Node.js
const response = await fetch(
"https://api.ops.tools/v1/ip/geolocation?ip=8.8.8.8",
{
headers: { "Authorization": "Bearer YOUR_API_KEY" }
}
);
const data = await response.json();
console.log(`Location: ${data.city}, ${data.country}`);
console.log(`ISP: ${data.isp}`);
console.log(`Timezone: ${data.timezone}`);
console.log(`VPN/Proxy: ${data.isVpn || data.isProxy}`);Go
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "https://api.ops.tools/v1/ip/geolocation?ip=8.8.8.8"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("Location: %s, %s\n", result["city"], result["country"])
fmt.Printf("ISP: %s\n", result["isp"])
}PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://api.ops.tools/v1/ip/geolocation?ip=8.8.8.8"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer YOUR_API_KEY"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
echo "Location: " . $data['city'] . ", " . $data['country'];
echo "ISP: " . $data['isp'];Common Use Cases
Fraud Detection
Flag transactions where the IP location does not match the billing address. Detect VPN and proxy usage to identify suspicious activity before it impacts your business.
Content Localization
Automatically display content in the user language and currency. Redirect to region-specific pages based on geolocation data for better user experience.
GDPR Compliance
Determine user jurisdiction for regulatory compliance. Apply appropriate data handling policies based on the user geographic location.
Analytics & Insights
Build geographic dashboards showing user distribution. Understand where your traffic comes from and identify growth opportunities in new regions.
VPN and Proxy Detection
Modern IP geolocation APIs include built-in VPN and proxy detection. This is essential for fraud prevention, ad verification, and security applications. The Ops.Tools API analyzes:
- Known VPN provider IP ranges (NordVPN, ExpressVPN, Cloudflare WARP, etc.)
- Data center IP patterns vs residential IPs
- Tor exit node identification
- Open proxy detection
- Residential proxy detection
# Check if an IP is using VPN or proxy
response = requests.get(apiUrl, headers=headers, params={"ip": user_ip})
data = response.json()
if data["isVpn"] or data["isProxy"]:
# Flag for manual review or block
flag_transaction(user_ip, reason="VPN/Proxy detected")
log_security_event(f"VPN/Proxy: {user_ip}")Check out our fraud prevention use case guide for a complete implementation pattern.
Bulk IP Geolocation for Log Analysis
For applications processing server logs or analyzing large IP datasets, the API supports batch operations. Process thousands of IP addresses efficiently:
Performance Tips for Bulk Processing
- Cache results for up to 7 days (IP locations rarely change)
- Use concurrent requests with a rate limiter
- Deduplicate IPs before querying
- Pre-process logs to extract unique IPs first
- Store results in your database for quick lookups
Frequently Asked Questions
Q: How accurate is IP geolocation?
Country-level accuracy is typically 99.9%+. City-level accuracy reaches 95%+ for most residential and business IPs. Data center and VPN IPs may only resolve to country level. The Ops.Tools database is continuously updated with new IP allocation data.
Q: Can IP geolocation detect VPNs?
Yes. The API analyzes IP address behavior, known VPN provider ranges, and data center IP patterns to identify VPN and proxy usage. Detection includes commercial VPN services, Tor exit nodes, open proxies, and residential proxies. This is essential for fraud prevention.
Q: Is IP geolocation legal?
IP geolocation is legal for business purposes. However, GDPR and other privacy regulations require transparency. You must inform users about IP data collection and explain how it is used. IP addresses are considered personal data under GDPR. Always consult your legal team for specific compliance requirements.
Q: What data does an IP geolocation API return?
The Ops.Tools API returns country, region, city, postal code, latitude, longitude, timezone, ISP name, ASN, organization, connection type, and VPN/proxy detection status. Coverage spans 240+ countries with continuous data updates.
Related Articles
DNS Lookup API: How to Check DNS Records Programmatically
Complete developer guide to querying DNS records via API. Includes working code examples in Python, Node.js, Go, and PHP with caching best practices.
Read ArticleWHOIS Lookup API: Domain Registration Data at Scale
Query WHOIS data programmatically for domain intelligence. Get registrar info, expiration dates, and ownership data. Python, Node.js, Go, and PHP examples.
Read ArticleAPI Integration Guide: Getting Started with Ops.Tools APIs
Complete getting started guide for DNS, WHOIS, IP, and SSL APIs. Authentication, code examples, caching strategies, and production deployment patterns.
Read ArticleStart Building Location-Aware Applications
Get professional IP geolocation data with VPN detection. Plans from $29/month for 6,000 lookups.