获取当前 IP - 文档 | Qianyun API

获取当前 IP

调用此 API 会返回查询服务器的 ip 或 js

请求URL

https://api.zhangxiaojie.tk/api/v1/ip
返回 JSON

响应体

JSON
{
  "code": 200,
  "version": "v1",
  "data": {
    "ip":"192.168.10.35"
}

解释

参数名称 返回值 参数说明 父集合
code 200 请求状态 null
version v1 版本信息 null
data { } 回调内容 null
ip xxxx IP data

请求URL

https://api.zhangxiaojie.tk/api/v1/ip?webrct=1
返回 JS

响应体

JS
async function detectWebRTCIPs(options = {}) {
    ……
}

使用方法

<script src="https://api.zhangxiaojie.tk/api/v1/ip?webrct=1"></script>

命令集

基础使用(默认配置)
JS
// 使用默认的 5 个 STUN 服务器
const result = await detectWebRTCIPs();
console.log('IPv4:', result.ipv4);
console.log('IPv6:', result.ipv6);
console.log('mDNS:', result.mdns);
console.log('所有 IP:', result.all);
console.log('分类详情:', result.classified);
只获取公网 IP
JS
const result = await detectWebRTCIPs({
    onlyPublic: true,  // 只返回公网 IP
    timeout: 3000
});
console.log('公网 IPv4:', result.ipv4);
console.log('公网 IPv6:', result.ipv6);
使用自定义 STUN 服务器
JS
const result = await detectWebRTCIPs({
    iceServers: [
        { urls: 'stun:stun.l.google.com:19302' },
        { urls: 'stun:stun.cloudflare.com:3478' }
    ]
});