feat(my-ip): 代理/VPN检测(proxycheck.io出口归属判定+WebRTC泄漏实测+本机内网IP)

This commit is contained in:
personal827 committed 2026-11-01 11:49:37 +08:00
1 parent 39ec9347e2
commit b4c4f5de8a
5 files changed
+240 -3

No files matched your search

+236
View File
@@ -1,6 +1,8 @@
<script setup lang="ts">
// 本机IP查询:用户端公网 IPv4/IPv6 + 归属地 + 本站IPv6直连 + 热门地点延迟 + 网速测试(浏览器 <-> 本站服务器真实收发)
type Geo = { country?: string; region?: string; city?: string; isp?: string; as?: string; lan?: boolean } | null;
// 代理/VPN 出口判定(relay /ip-check 返回)
type ChkInfo = { ip?: string; lan?: boolean; proxy?: boolean | null; type?: string; provider?: string; hostname?: string; asn?: string } | null;
// ---------- IP 查询(仅用户端视角,不显示服务器地址) ----------
const ipLoading = ref(true);
@@ -97,6 +99,110 @@ async function loadIps() {
v4Geo.value = g4;
v6Geo.value = g6;
ipLoading.value = false;
// 拿到地址后并行做代理/VPN 检测(不阻塞主卡片)
runProxyCheck();
rtcProbe();
}
// ---------- 代理/VPN 检测(出口 IP 判定 + WebRTC 泄漏检测,均免费) ----------
const pcLoading = ref(false);
const chk4 = ref<ChkInfo | null>(null); // v4 出口判定
const chk6 = ref<ChkInfo | null>(null); // v6 出口判定
const rtcPub = ref<string[]>([]); // STUN 实测公网候选(代理漏出的真实地址线索)
const rtcLocal = ref<string[]>([]); // 本机内网候选
const rtcState = ref<'wait' | 'run' | 'done'>('wait');
async function runProxyCheck() {
if (!v4.value && !v6.value) return;
pcLoading.value = true;
const [c4, c6] = await Promise.all([
v4.value ? jfetch(`/relay/ip-check?ip=${encodeURIComponent(v4.value)}`, 12000).catch(() => null) : null,
v6.value ? jfetch(`/relay/ip-check?ip=${encodeURIComponent(v6.value)}`, 12000).catch(() => null) : null,
]);
chk4.value = (c4 && c4.data) || null;
chk6.value = (c6 && c6.data) || null;
pcLoading.value = false;
}
// WebRTC 探测:STUN srflx 候选=公网(代理/VPN 漏洞常见线索);host 候选=本机内网 IP。
// Chrome 会把 host 候选打成 mDNS(.local) 域名,此时内网 IP 显示为「浏览器隐私保护已隐藏」。
async function rtcProbe() {
if (typeof RTCPeerConnection === 'undefined') {
rtcState.value = 'done';
return;
}
rtcState.value = 'run';
const pub = new Set<string>();
const loc = new Set<string>();
let pc: RTCPeerConnection;
try {
pc = new RTCPeerConnection({
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' },
],
});
} catch {
rtcState.value = 'done';
return;
}
try {
pc.createDataChannel('probe');
pc.onicecandidate = (e) => {
if (!e.candidate) return;
const m = /candidate:\S+ \d+ \S+ \d+ (\S+) \d+ typ (\w+)/.exec(e.candidate.candidate);
if (!m) return;
const ip = m[1].split('%')[0]; // 去 zone id
const typ = m[2];
if (ip.includes('.local')) return; // mDNS 伪地址,忽略
if (typ === 'srflx') pub.add(ip);
else if (typ === 'host') {
const v4m = ip.match(/^(\d+)\./);
const priv4 = v4m && ['10', '172', '192', '169'].includes(v4m[1]);
const priv6 = ip.startsWith('fe80') || ip.startsWith('fc') || ip.startsWith('fd');
if (ip.includes(':') ? priv6 : priv4) loc.add(ip); // 只留私网地址,公网 host 候选归入 pub 语义
else pub.add(ip);
}
};
pc.createOffer().then((o) => pc.setLocalDescription(o)).catch(() => {});
await new Promise<void>((res) => {
const to = setTimeout(res, 6000);
pc.onicecandidate = ((orig) => (e: RTCPeerConnectionIceEvent) => {
orig(e);
if (!e.candidate) {
clearTimeout(to);
res();
}
})(pc.onicecandidate!);
});
} catch {
/* 探测失败按无候选处理 */
}
try {
pc.close();
} catch {
/* ignore */
}
rtcPub.value = [...pub];
rtcLocal.value = [...loc];
rtcState.value = 'done';
}
// WebRTC 公网候选与主 IP 不一致的地址(可能的真实出口)
const rtcMismatch = computed<string[]>(() => {
const known = new Set([v4.value, v6.value].filter(Boolean));
return rtcPub.value.filter((ip) => !known.has(ip));
});
function chkVerdict(c: ChkInfo | null): { icon: string; text: string; cls: string } {
if (pcLoading.value) return { icon: '⏳', text: '检测中…', cls: '' };
if (!c) return { icon: '⚪', text: '无法判定(查询服务暂不可用)', cls: 'px-unknown' };
if (c.lan) return { icon: '🏠', text: '内网地址,不适用代理判定', cls: '' };
if (c.proxy) return { icon: '🔴', text: `检测到代理/VPN(${c.type}${c.provider ? ' · ' + c.provider : ''})`, cls: 'px-bad' };
if (c.type === 'Business' || c.type === 'Hosting') {
return { icon: '🟡', text: `${c.type === 'Hosting' ? '数据中心' : '企业'}网络出口,通常非家庭宽带`, cls: 'px-warn' };
}
return { icon: '🟢', text: `未检测到代理/VPN(${c.type || '家庭宽带线路'}${c.provider ? ' · ' + c.provider : ''})`, cls: 'px-ok' };
}
function geoLine(g: Geo): string {
@@ -513,6 +619,54 @@ onMounted(() => {
</div>
</div>
<!-- 代理 / VPN 检测(出口 IP 判定 + WebRTC 泄漏检测) -->
<div v-if="v4 || v6" class="sec">
<div class="sec-head">
<h3>🕵 代理 / VPN 检测</h3>
<button class="sec-refresh" :disabled="pcLoading" @click="runProxyCheck()">
{{ pcLoading ? '检测中…' : '重新检测' }}
</button>
</div>
<div class="px-rows">
<div class="px-row">
<span class="px-k">IPv4 出口判定</span>
<span class="px-v" :class="chkVerdict(chk4).cls">{{ chkVerdict(chk4).icon }} {{ chkVerdict(chk4).text }}</span>
</div>
<div v-if="v6" class="px-row">
<span class="px-k">IPv6 出口判定</span>
<span class="px-v" :class="chkVerdict(chk6).cls">{{ chkVerdict(chk6).icon }} {{ chkVerdict(chk6).text }}</span>
</div>
<div class="px-row">
<span class="px-k">WebRTC 实测公网地址</span>
<span class="px-v">
<template v-if="rtcState === 'run'">⏳ 探测中…</template>
<template v-else-if="rtcPub.length">
<code v-for="ip in rtcPub" :key="ip" class="px-ip">{{ ip }}</code>
<template v-if="rtcMismatch.length">
<span class="px-bad">⚠ 与上方 IP 不一致:{{ rtcMismatch.join('、') }} —— 浏览器经 STUN 拿到的另一公网地址,若你在用代理/VPN,这可能才是你的实际网络出口</span>
</template>
<template v-else>
<span class="px-ok">✓ 与上方一致</span>
</template>
</template>
<template v-else>未检出(浏览器已禁用 WebRTC,或被代理软件/网络阻断 STUN)</template>
</span>
</div>
<div class="px-row">
<span class="px-k">本机内网 IP</span>
<span class="px-v">
<template v-if="rtcState === 'run'">⏳ 探测中…</template>
<template v-else-if="rtcLocal.length">
<code v-for="ip in rtcLocal" :key="ip" class="px-ip">{{ ip }}</code>
</template>
<template v-else-if="rtcState === 'done'">浏览器隐私保护已隐藏(现代 Chrome 默认用虚拟域名代替)</template>
<template v-else>—</template>
</span>
</div>
</div>
<p class="px-note">说明:浏览器无法直接读取系统代理软件的开关状态;判定依据为出口 IP 归属数据库(proxycheck.io)与 WebRTC 泄漏实测——高级代理/VPN 可能伪装归属地或阻断 STUN,结果仅供参考。</p>
</div>
<!-- 热门地点延迟 -->
<div class="sec">
<div class="sec-head">
@@ -876,6 +1030,88 @@ onMounted(() => {
margin-top: 10px;
}
/* ---------- 代理/VPN 检测 ---------- */
.px-rows {
font-size: 14px;
.px-row {
display: flex;
align-items: baseline;
gap: 10px;
padding: 7px 0;
border-bottom: 1px dashed rgba(128, 128, 128, 0.18);
&:last-child {
border-bottom: none;
}
.px-k {
flex: 0 0 150px;
opacity: 0.75;
font-weight: 600;
font-size: 13px;
}
.px-v {
flex: 1;
min-width: 0;
line-height: 1.6;
}
}
}
.px-ip {
font-family: monospace;
background: rgba(128, 128, 128, 0.12);
padding: 1px 8px;
border-radius: 6px;
margin-right: 8px;
font-size: 13px;
word-break: break-all;
}
.px-ok {
color: #18a058;
}
.px-warn {
color: #d0a000;
}
.px-bad {
color: #d03050;
}
.px-unknown {
opacity: 0.6;
}
.px-note {
margin-top: 8px;
font-size: 12.5px;
opacity: 0.65;
line-height: 1.7;
}
.sec-refresh {
border: 1px solid rgba(128, 128, 128, 0.35);
background: transparent;
color: inherit;
border-radius: 8px;
padding: 5px 14px;
font-size: 13px;
cursor: pointer;
&:disabled {
opacity: 0.5;
cursor: default;
}
&:hover:not(:disabled) {
border-color: rgba(128, 128, 128, 0.7);
}
}
/* ---------- 测速历史 ---------- */
.sp-history {
margin-top: 14px;