IP位置查询API

概述

本API提供IP位置查询

快速开始

基础请求

GET https://ip.api.opens.ltd/public.php?ip=8.8.8.8

响应示例

{  
    "success": true,
    "data": {
        "ip": "8.8.8.8",
        "city_id": 2056,
        "region": "美国|0|0|Level3",
        "country": "美国",
        "country_code": "US",
        "country_info": {
            "chinese": "美国",
            "english": "United States of America",
            "alpha2": "US",
            "alpha3": "USA",
            "numeric": "840"
        },
        "province": "",
        "city": "",
        "isp": "Level3",
        "simple": "美国【Level3】"
    },
    "rate_limit": {
        "limit": 60,
        "remaining": 59,
        "reset_time": 1758409135
    }
}

API接口

请求地址

POST/GET https://ip.api.opens.ltd/public.php

请求方式

1. GET请求(推荐)

curl "https://ip.api.opens.ltd/public.php?ip=61.142.118.231"

2. POST表单请求

curl -X POST -d "ip=61.142.118.231" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     "https://ip.api.opens.ltd/public.php"

3. POST JSON请求

curl -X POST -d '{"ip":"61.142.118.231"}' \
     -H "Content-Type: application/json" \
     "https://ip.api.opens.ltd/public.php"

4. 请求头方式

curl -H "X-IP: 61.142.118.231" \
     "https://ip.api.opens.ltd/public.php"

请求参数

参数 类型 必填 说明
ip string IPv4地址

注意

IP参数只能在一个位置提供,如果同时在多个位置出现会返回400错误。

响应格式

成功响应

HTTP状态码:200 OK

字段 类型 说明
success boolean 请求是否成功
data object IP地理位置信息
data.ip string 查询的IP地址
data.city_id integer 城市ID
data.region string 原始地理信息(格式:国家|省份|城市|ISP)
data.country string 国家名称(中文)
data.country_code string 国家代码(ISO 3166-1 alpha-2)
data.country_info object 详细国家信息
data.country_info.chinese string 中文国家名称
data.country_info.english string 英文国家名称
data.country_info.alpha2 string ISO 3166-1 alpha-2代码
data.country_info.alpha3 string ISO 3166-1 alpha-3代码
data.country_info.numeric string ISO 3166-1数字代码
data.province string 省份/州名称
data.city string 城市名称
data.isp string 网络服务提供商
data.simple string 简化显示格式
rate_limit object 速率限制信息
rate_limit.limit integer 每分钟请求限制
rate_limit.remaining integer 剩余请求次数
rate_limit.reset_time integer 限制重置时间(Unix时间戳)

错误处理

错误响应格式

{
    "success": false,
    "error": {
        "code": 400,
        "message": "错误描述"
    },
    "rate_limit": {
        "limit": 60,
        "remaining": 59,
        "reset_time": 1758409135
    }
}

错误代码说明

HTTP状态码 错误代码 说明
400 400 请求参数错误(缺少IP参数或IP格式无效)
400 400 IP参数在多个位置重复提供
429 429 请求频率超限(每分钟超过60次)
500 500 服务器内部错误

速率限制

限制规则

响应头信息

每个响应都包含速率限制信息:

超限处理

当请求超过限制时,API将返回HTTP 429状态码,建议客户端实现指数退避重试策略。

感谢使用

若您想使用无速率限制的api,可以把public.php换成api.php。但不要贪杯哦~

© 2025 AIXIAOJI