免费IP地址查询API接口推荐

作者:youqing · 2025-11-06 · 阅读时间:7分钟

收藏它,10 分钟接入全球 IP 定位,精准到城市级别!


一、IP 地址查询 API:查询本机 IP 或通过 IP 反查 🔍

1. IP.CN API 🇨🇳

  • URL: https://www.ip.cn/api/index?ip=&type=0

  • 请求类型: GET

  • 示例:

    import requests
    response = requests.get("https://www.ip.cn/api/index?ip=121.8.215.106&type=1")
    print(response.json())

    代码示例讲解概念 一行行对比 type=0 vs type=1 返回字段差异!

  • 结果示例:

    {
    "rs": 1,
    "code": 0,
    "address": "中国  广东省 广州市 电信",
    "ip": "121.8.215.106",
    "isDomain": 0
    }

2. PConline API 📡

  • URL: https://whois.pconline.com.cn/ipJson.jsp?ip=&json=true

  • 示例:

    response = requests.get("https://whois.pconline.com.cn/ipJson.jsp?ip=121.8.215.106&json=true")
    print(response.json())

    代码片段解析助手 秒懂 cityCode 与国家统计局编码的对应关系!

  • 结果示例:

    {
    "ip": "121.8.215.106",
    "pro": "广东省",
    "city": "广州市",
    "cityCode": "440100",
    "addr": "广东省广州市 电信"
    }

3. Vore API 🌐

  • URL: https://api.vore.top/api/IPdata?ip=

  • 支持 CORS

  • 示例:

    response = requests.get("https://api.vore.top/api/IPdata?ip=121.8.215.106")
    print(response.json())

    代码优化助手requests.get 改为 requests.Session 连接池,QPS 提升 3 倍!

  • 结果示例:

    {
    "code": 200,
    "ipdata": {
    "info1": "广东省",
    "info2": "广州市",
    "info3": "增城",
    "isp": "电信"
    },
    "adcode": {
    "a": "440100",
    "i": true
    }
    }

4. IP.sb API 🗺️

  • URL: https://api.ip.sb/geoip/

  • 支持 CORS

  • 示例:

    response = requests.get("https://api.ip.sb/geoip/121.8.215.106")
    print(response.json())

    JavaScript代码反混淆专家 解开前端 SDK 的混淆代码,确保经纬度精度不被截断!

  • 结果示例:

    {
    "city": "Guangzhou",
    "region": "Guangdong",
    "country": "China",
    "latitude": 23.1181,
    "longitude": 113.2539,
    "isp": "China Telecom"
    }

5. IP2Location API 📍

  • URL: https://api.ip2location.io/

  • 限制: 500 次/天

  • 示例:

    response = requests.get("https://api.ip2location.io/?ip=121.8.215.106")
    print(response.json())

    代码安全审查 扫描 is_proxy 字段,自动标记代理 IP 并触发二次验证!

  • 结果示例:

    {
    "ip": "121.8.215.106",
    "country_name": "China",
    "region_name": "Guangdong",
    "city_name": "Guangzhou",
    "latitude": 23.127361,
    "longitude": 113.26457,
    "is_proxy": true
    }

二、IP 地址归属地查询 API:仅查询本机 IP 信息 🏠

Httpbin API 🕸️

  • URL: http://httpbin.org/ip
  • 不支持 CORS
  • 示例:
    response = requests.get("http://httpbin.org/ip")
    print(response.json())
  • 结果:
    { "origin": "20.249.16.173" }

三、IP 地址归属地查询 API:只可通过 IP 查询信息 🔍

Baidu OpenData API 🍴

GeoJS API 🌍

  • URL: https://get.geojs.io/v1/ip/geo/{ip}.json

  • 支持 CORS

  • 示例:

    response = requests.get("https://get.geojs.io/v1/ip/geo/121.8.215.106.json")
    print(response.json())

    API交互代码生成 30 秒生成带「指数退避 + 缓存」的批量查询脚本,1 分钟跑完 1000 条!

  • 结果示例:

    {
    "country": "China",
    "city": "Guangzhou",
    "latitude": "23.1181",
    "longitude": "113.2539",
    "accuracy": 1000
    }

IPinfo API 🛡️

  • URL: https://ipinfo.io/widget/demo/{ip}

  • 支持 CORS

  • 示例:

    response = requests.get("https://ipinfo.io/widget/demo/121.8.215.106")
    print(response.json())

    代码优化专家助手response.json() 改为 response.json()['data'],减少一次字典拷贝!

  • 结果示例:

    {
    "data": {
    "ip": "121.8.215.106",
    "city": "Shenzhen",
    "country": "CN",
    "loc": "22.5455,114.0683",
    "org": "AS4134 CHINANET-BACKBONE",
    "privacy": { "vpn": false, "proxy": false }
    }
    }

四、总结 🏁

IP 地址查询 API 是精准定位、数据分析、个性化营销的利器:

  • 免费易集成多语言支持
  • 支持全球定位运营商识别代理检测
  • 10 分钟接入,立刻提升应用功能与用户体验!

现在就复制文中的 Python 代码,10 分钟跑通全球 IP 定位,让你的应用「一眼看穿」用户来源!