MCPcopy Create free account
hub / github.com/cmliu/CF-Workers-CheckProxyIP / getExitFamily

Function getExitFamily

_worker.js:5552–5562  ·  view source on GitHub ↗
(result)

Source from the content-addressed store, hash-verified

5550
5551// 优先使用探针返回的 ipType;若没有 ipType,再回退到根据出口 IP 字符串判定。
5552function 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
5564async function handleCheckProxyRequest(req) {
5565 if (req.method === 'OPTIONS') {

Callers 1

handleCheckProxyRequestFunction · 0.85

Calls 1

pickExitIpFunction · 0.85

Tested by

no test coverage detected