手机版 收藏 导航

ip查询api接口文档

原创   www.link114.cn   2025-03-11 08:02:44

ip查询api接口文档

该API接口提供以下功能:

  • 根据IP地址获取地理位置信息,包括国家、省份、城市、经纬度等
  • 获取IP地址的所属运营商信息
  • 查询IP地址的归属地信息
  • 提供IP地址的历史解析记录
  • 支持批量查询,可一次性查询多个IP地址

接口地址: https://api.example.com/v1/ip

参数名称 参数类型 是否必填 说明
ip string 需要查询的IP地址,支持单个IP地址或多个IP地址,多个IP地址以逗号分隔
format string 返回数据的格式,可选值为json或xml,默认为json

API接口返回的数据格式为JSON或XML,具体取决于请求时设置的format参数。以下为JSON格式的返回数据示例:

{
  "data": [
    {
      "ip": "8.8.8.8",
      "country": "United States",
      "region": "California",
      "city": "Mountain View",
      "latitude": 37.4192,
      "longitude": -122.0574,
      "isp": "Google LLC"
    },
    {
      "ip": "114.114.114.114",
      "country": "China",
      "region": "Beijing",
      "city": "Beijing",
      "latitude": 39.9075,
      "longitude": 116.3972,
      "isp": "China Unicom"
    }
  ]
}

请求失败,API接口将返回相应的错误信息,包括错误代码和错误描述。例如:

{
  "error": {
    "code": 400,
    "message": "Invalid IP address format"
  }
}

以下是使用Python的requests库进行API调用的示例代码:

import requests

url = "https://api.example.com/v1/ip"
params = {
    "ip": "8.8.8.8,114.114.114.114"
}

response = requests.get(url, params=params)
if response.status_code == 200:
    data = response.json()
    print(data)
else:
    error = response.json()
    print(f"Error {error['error']['code']}: {error['error']['message']}")