API Documentation

IP2Region Offline Geolocation Service — Supports IPv4 & IPv6

1. Query IP Location

GET https?action=query&ip={ip}

Query geographic location by IP address.

ParameterTypeRequiredDescription
ipstringYesIPv4 or IPv6 address
Request
GET https?action=query&ip=8.8.8.8
Response
{
  "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"
  }
}
POST https?action=query

Query IP location via POST. Supports application/json and application/x-www-form-urlencoded.

ParameterTypeRequiredDescription
ipstringYesIPv4 or IPv6 address
cURL (JSON)
curl -X POST https?action=query \
  -H "Content-Type: application/json" \
  -d '{"ip": "8.8.8.8"}'
cURL (Form)
curl -X POST https?action=query \
  -d "ip=8.8.8.8"

2. Get My IP

GET https?action=myip

Returns the caller's IP address and its geographic location.

Request
GET https?action=myip
Response
{
  "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
  }
}

3. Service Info

GET https?action=info

Returns API service metadata and available endpoints.

Request
GET https?action=info

4. Error Response

All errors follow the same format with code ≠ 0.

{
  "code": 1,
  "message": "Invalid IP address format",
  "data": null
}

5. Quick Integration

JavaScript (Fetch)
fetch('https?action=myip')
  .then(r => r.json())
  .then(d => console.log(d.data.ip, d.data.location));
Python (Requests)
import requests
r = requests.get('https', params={'action': 'query', 'ip': '8.8.8.8'})
print(r.json())
PHP (cURL)
$ch = curl_init('https?action=myip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch), true);
echo $result['data']['ip'];
← Back to My IP