import{_ as n,c as a,a as t,o as l}from"./app-Dgsdh8A6.js";const e={};function o(p,s){return l(),a("div",null,s[0]||(s[0]=[t(`

通过ip确定地理位置

根据请求IP确定属地

https://api.bilibili.com/x/web-interface/zone

https://api.live.bilibili.com/xlive/web-room/v1/index/getIpInfo

https://app.bilibili.com/x/resource/ip

请求方式:GET

json回复:

根对象:

字段类型内容备注
codenum返回值0:成功
messagestr错误信息默认为0
ttlnum1
dataobj信息本体

data对象:

字段类型内容备注
addrstr公网IP地址
countrystr国家/地区名
provincestr省/州非必须存在项
citystr城市非必须存在项
ispstr运营商名
latitudenum纬度
longitudenum经度
zone_idnumip数据库id第二个接口无
country_codenum国家/地区代码第二个接口无

示例:

curl 'https://api.bilibili.com/x/web-interface/zone'
查看响应示例:
{
    "code":0,
    "message":"0",
    "ttl":1,
    "data":{
            "addr":"36.40.120.145",
            "country":"中国",
            "province":"陕西",
            "city":"渭南",
            "isp":"电信",
            "latitude":34.4995,
            "longitude":109.492821,
            "zone_id":4472912,
            "country_code":86
        }
}

查询任意 IP 地址的归属地

https://api.live.bilibili.com/ip_service/v1/ip_service/get_ip_addr
https://api.live.bilibili.com/client/v1/Ip/getInfoNew

注: 以上接口等效

请求方式:GET

URL参数:

参数名类型内容必要性备注
ipstrIP地址不必要IPv4或IPv6地址不限, 留空与根据请求IP确定地理位置基本相同

JSON回复:

根对象:

字段类型内容备注
codenum返回值0: 成功
messagestr错误信息默认为空
msgstr错误信息同message
dataobj信息本体出错时为空数组

data对象:

根据请求IP确定地理位置回复的data对象基本相同, 但无 zone_id country_code 字段

示例:

查询请求IP地址的归属地:

curl -G 'https://api.live.bilibili.com/client/v1/Ip/getInfoNew'
查看响应示例:
{
  "code": 0,
  "msg": "",
  "message": "",
  "data": {
    "addr": "104.28.156.113",
    "country": "新加坡",
    "province": "新加坡",
    "city": "",
    "isp": "cloudflare.com",
    "latitude": "1.352083",
    "longitude": "103.819836"
  }
}

查询IP地址8.8.8.8的归属地:

curl -G 'https://api.live.bilibili.com/ip_service/v1/ip_service/get_ip_addr' \\
--data-urlencode 'ip=8.8.8.8'
查看响应示例:
{
  "code": 0,
  "msg": "",
  "message": "",
  "data": {
    "addr": "8.8.8.8",
    "country": "GOOGLE.COM",
    "province": "GOOGLE.COM",
    "city": "",
    "isp": "level3.com",
    "latitude": "",
    "longitude": ""
  }
}
`,30)]))}const r=n(e,[["render",o]]),c=JSON.parse('{"path":"/docs/clientinfo/ip.html","title":"通过ip确定地理位置","lang":"zh-CN","frontmatter":{},"git":{"updatedTime":1750530532000,"contributors":[{"name":"SocialSisterYi","username":"SocialSisterYi","email":"1440239038@qq.com","commits":2,"url":"https://github.com/SocialSisterYi"},{"name":"SessionHu","username":"SessionHu","email":"102411014+SessionHu@users.noreply.github.com","commits":2,"url":"https://github.com/SessionHu"},{"name":"114514ns","username":"114514ns","email":"121270969+114514ns@users.noreply.github.com","commits":1,"url":"https://github.com/114514ns"}],"changelog":[{"hash":"2f48f6c81ab400d03ac40921b25906ad8719e725","time":1750530532000,"email":"121270969+114514ns@users.noreply.github.com","author":"114514ns","message":"添加部分直播相关api (#1297)"},{"hash":"60a0c5d1a2f44fe61335da04571305fa7727a968","time":1724238159000,"email":"102411014+SessionHu@users.noreply.github.com","author":"Session小胡","message":"feat: 各种接口补充与错误修正 (#1066)"},{"hash":"18c1efbc102ae6b44c8f5314c90e5e64f0d926cd","time":1721909032000,"email":"102411014+SessionHu@users.noreply.github.com","author":"Session小胡","message":"feat: bili_ticket 算法 Java 实现 及 信息补充 及 错误修正 (#1061)"},{"hash":"f6760f4be38d5b592d396b211e48c666286524de","time":1677124138000,"email":"1440239038@qq.com","author":"SocialSisterYi","message":"🔨remove header index"},{"hash":"7d89ece2ac46425810647c4ac92acf5f3721cb68","time":1676998806000,"email":"1440239038@qq.com","author":"SocialSisterYi","message":"🚀调整项目结构"}]},"filePathRelative":"docs/clientinfo/ip.md"}');export{r as comp,c as data};