(result)
| 5550 | |
| 5551 | // 优先使用探针返回的 ipType;若没有 ipType,再回退到根据出口 IP 字符串判定。 |
| 5552 | function getExitFamily(result) { |
| 5553 | if (!result?.ok) return null; |
| 5554 | const ipType = `${result?.exit?.ipType ?? ''}`.toLowerCase(); |
| 5555 | if (ipType === 'ipv4' || ipType === 'ipv6') return ipType; |
| 5556 | const exitIp = pickExitIp(result.exit) ?? ''; |
| 5557 | // IPv4:必须匹配 x.x.x.x 且每段 0-255。 |
| 5558 | if (/^\d{1,3}(?:\.\d{1,3}){3}$/.test(exitIp) && exitIp.split('.').every((part) => Number(part) <= 255)) return 'ipv4'; |
| 5559 | // IPv6:当前逻辑只要包含 ":" 就视为 IPv6(未做完整 RFC 严格校验)。 |
| 5560 | if (exitIp.includes(':')) return 'ipv6'; |
| 5561 | return null; |
| 5562 | } |
| 5563 | |
| 5564 | async function handleCheckProxyRequest(req) { |
| 5565 | if (req.method === 'OPTIONS') { |
no test coverage detected