跳转至

如何获取 IP 地址信息

概要: 几种通过 API 方式,免费获取 IP 地址信息的方式

创建时间: 2023.12.01 23:20:05

更新时间: 2023.12.02 01:41:50

ip-api.com

特点

  • 无需注册

请求

Bash
curl "http://ip-api.com/json/117.136.12.79"
响应
Bash
{
  "status": "success",
  "country": "China",
  "countryCode": "CN",
  "region": "GD",
  "regionName": "Guangdong",
  "city": "Guangzhou",
  "zip": "",
  "lat": 23.1291,
  "lon": 113.2643,
  "timezone": "Asia/Shanghai",
  "isp": "China Mobile communications corporation",
  "org": "China Mobile",
  "as": "AS56040 China Mobile communications corporation",
  "query": "117.136.12.79"
}

ipinfo.io

特点

  • 需要注册,利用 TOKEN 作为参数请求
  • 免费用户每月 50000 次请求限制
  • 付费用户可以获取更多的详情信息
  • 官方提供 Python 库

示例请求

Bash
curl "ipinfo.io/117.136.12.79?token=TOKEN"
示例响应
Bash
1
2
3
4
5
6
7
8
9
{
  "ip": "117.136.12.79",
  "city": "Guangzhou",
  "region": "Guangdong",
  "country": "CN",
  "loc": "23.1167,113.2500",
  "org": "AS56040 China Mobile communications corporation",
  "timezone": "Asia/Shanghai"
}

ipgeolocation.io

特点

  • 需要注册,利用 API_KEY 作为参数请求
  • 免费用户每月 1000 次请求限制

示例请求

Bash
curl "https://api.ipgeolocation.io/ipgeo?apiKey=API_KEY&ip=117.136.12.79"
示例响应
Bash
{
  "ip": "117.136.12.79",
  "continent_code": "AS",
  "continent_name": "Asia",
  "country_code2": "CN",
  "country_code3": "CHN",
  "country_name": "China",
  "country_name_official": "People’s Republic of China",
  "country_capital": "Beijing",
  "state_prov": "Guangdong",
  "state_code": "CN-GD",
  "district": "",
  "city": "Guangzhou",
  "zipcode": "510100",
  "latitude": "23.12518",
  "longitude": "113.28064",
  "is_eu": false,
  "calling_code": "+86",
  "country_tld": ".cn",
  "languages": "zh-CN,yue,wuu,dta,ug,za",
  "country_flag": "https://ipgeolocation.io/static/flags/cn_64.png",
  "geoname_id": "10285766",
  "isp": "China Mobile/Base Station WiFi",
  "connection_type": "",
  "organization": "China Mobile",
  "currency": {
    "code": "CNY",
    "name": "Yuan Renminbi",
    "symbol": "¥"
  },
  "time_zone": {
    "name": "Asia/Shanghai",
    "offset": 8,
    "offset_with_dst": 8,
    "current_time": "2023-12-01 22:50:28.017+0800",
    "current_time_unix": 1701442228.017,
    "is_dst": false,
    "dst_savings": 0
  }
}

ipstack.com

特点

  • 需要注册,利用 ACCESS_KEY 作为参数请求
  • 免费用户每月 1000 次请求限制

示例请求

Bash
curl "http://api.ipstack.com/117.136.12.79?access_key=ACCESS_KEY"
示例响应
Bash
{
  "ip": "117.136.12.79",
  "type": "ipv4",
  "continent_code": "AS",
  "continent_name": null,
  "country_code": "CN",
  "country_name": null,
  "region_code": "GD",
  "region_name": "Guangdong",
  "city": "Guangzhou",
  "zip": "510500",
  "latitude": 23.143600463867188,
  "longitude": 113.33399963378906,
  "location": {
    "geoname_id": 1809858,
    "capital": "Beijing",
    "languages": [
      {
        "code": "zh",
        "name": "Chinese",
        "native": "\u4e2d\u6587"
      }
    ],
    "country_flag": "https://assets.ipstack.com/flags/cn.svg",
    "country_flag_emoji": "\ud83c\udde8\ud83c\uddf3",
    "country_flag_emoji_unicode": "U+1F1E8 U+1F1F3",
    "calling_code": "86",
    "is_eu": false
  }
}

参考