IP2Region Offline Geolocation Service — Supports IPv4 & IPv6
Query geographic location by IP address.
| Parameter | Type | Required | Description |
|---|---|---|---|
| ip | string | Yes | IPv4 or IPv6 address |
GET https?action=query&ip=8.8.8.8
{
"code": 0,
"message": "success",
"data": {
"ip": "8.8.8.8",
"ip_version": "IPv4",
"country": "美国",
"province": "加利福尼亚",
"city": "洛杉矶",
"isp": "Google",
"country_code": "US",
"location": "美国加利福尼亚洛杉矶",
"raw": "美国|加利福尼亚|洛杉矶|Google|US"
}
}
Query IP location via POST. Supports application/json and application/x-www-form-urlencoded.
| Parameter | Type | Required | Description |
|---|---|---|---|
| ip | string | Yes | IPv4 or IPv6 address |
curl -X POST https?action=query \
-H "Content-Type: application/json" \
-d '{"ip": "8.8.8.8"}'
curl -X POST https?action=query \ -d "ip=8.8.8.8"
Returns the caller's IP address and its geographic location.
GET https?action=myip
{
"code": 0,
"message": "success",
"data": {
"ip": "203.0.113.50",
"ip_version": "IPv4",
"country": "中国",
"province": "广东",
"city": "深圳",
"isp": "电信",
"country_code": "CN",
"location": "中国广东深圳",
"raw": "中国|广东|深圳|电信|CN",
"is_private": false
}
}
Returns API service metadata and available endpoints.
GET https?action=info
All errors follow the same format with code ≠ 0.
{
"code": 1,
"message": "Invalid IP address format",
"data": null
}
fetch('https?action=myip')
.then(r => r.json())
.then(d => console.log(d.data.ip, d.data.location));
import requests
r = requests.get('https', params={'action': 'query', 'ip': '8.8.8.8'})
print(r.json())
$ch = curl_init('https?action=myip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch), true);
echo $result['data']['ip'];