Skip to content

Instantly share code, notes, and snippets.

@sibosend
Created October 31, 2025 05:54
Show Gist options
  • Select an option

  • Save sibosend/abb03b9af10806dcf47a1aacbc421c65 to your computer and use it in GitHub Desktop.

Select an option

Save sibosend/abb03b9af10806dcf47a1aacbc421c65 to your computer and use it in GitHub Desktop.
gistforfun
function FindProxyForURL(url, host) {
// ==================== 配置区域 ====================
// SOCKS5 代理配置
var PROXY = "SOCKS5 127.0.0.1:1080";
// 需要走代理的域名列表(支持通配符)
var proxyDomains = [
"server-urule-prod.tidbi-it.cc",
"server-urule-pre.tidbi-it.cc",
];
// 需要走代理的 IP 列表(CIDR 或单个 IP)
var proxyIPs = [
//{ip: "1.1.1.1", mask: "255.255.255.255"}, // 单个 IP
//{ip: "192.168.1.0", mask: "255.255.255.0"}, // 192.168.1.0/24 网段
//{ip: "10.0.0.0", mask: "255.0.0.0"} // 10.0.0.0/8 网段
];
// 需要直连的域名(优先级更高,即使在 proxyDomains 中也直连)
var directDomains = [
"*.baidu.com",
];
// ==================== 逻辑处理 ====================
// 1. 检查直连白名单(优先级最高)
for (var i = 0; i < directDomains.length; i++) {
if (shExpMatch(host, directDomains[i])) {
return "DIRECT";
}
}
// 2. 检查域名代理列表
for (var i = 0; i < proxyDomains.length; i++) {
if (shExpMatch(host, proxyDomains[i])) {
return PROXY;
}
}
// 3. 检查 IP 代理列表
for (var i = 0; i < proxyIPs.length; i++) {
if (isInNet(host, proxyIPs[i].ip, proxyIPs[i].mask)) {
return PROXY;
}
}
// 4. 本地地址直连
if (isPlainHostName(host) ||
shExpMatch(host, "*.local") ||
isInNet(host, "127.0.0.0", "255.0.0.0") ||
isInNet(host, "10.0.0.0", "255.0.0.0") ||
isInNet(host, "172.16.0.0", "255.240.0.0") ||
isInNet(host, "192.168.0.0", "255.255.0.0")) {
return "DIRECT";
}
// 5. 默认直连
return "DIRECT";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment