/**
* ============================================================
* Clash Verge Rev / Mihomo
*
* CN -> DIRECT
* Overseas -> PRIVACY
*
* PRIVACY = manual node selection
*
* DNS:
* CN -> AliDNS / DNSPod directly
* Overseas -> Cloudflare / Google through PRIVACY
*
* TUN:
* Enabled
* System Stack
* DNS Hijack
* Strict Route
*
* No latency test
* No automatic node switching
* No failover
* ============================================================
*/
const PRIVACY_GROUP = "PRIVACY";
/* ============================================================
* Hide subscription groups
* ============================================================ */
const HIDDEN_GROUPS = new Set([
"飞鸟云",
"自动选择",
"故障转移"
]);
/* ============================================================
* Filter information nodes
* ============================================================ */
const INFO_NODE_FILTER =
"(?i)" +
"剩余流量|" +
"套餐到期|" +
"到期时间|" +
"流量重置|" +
"官网|" +
"客服|" +
"公告|" +
"最新网址";
/* ============================================================
* MAIN
* ============================================================ */
function main(config, profileName) {
if (
!config ||
typeof config !== "object"
) {
throw new Error("Invalid Mihomo configuration");
}
/* ==========================================================
* Basic
* ========================================================== */
config.mode = "rule";
/*
* Your physical WLAN currently has no useful native IPv6
* Internet connectivity.
*
* Disable IPv6 to avoid unnecessary AAAA / IPv6 attempts.
*/
config.ipv6 = false;
/*
* Connect to all DNS-resolved IP addresses concurrently
* and use the first successful connection.
*/
config["tcp-concurrent"] = true;
/*
* Preserve selected proxy and fake-ip mapping.
*/
config.profile = {
...(config.profile || {}),
"store-selected": true,
"store-fake-ip": true
};
/* ==========================================================
* DNS
* ========================================================== */
config.dns = {
enable: true,
/*
* Local DNS listener.
*/
listen: "127.0.0.1:1053",
/*
* Disable AAAA responses for now.
*/
ipv6: false,
/*
* DNS cache.
*/
"cache-algorithm": "arc",
/*
* respect-rules + prefer-h3 is not recommended.
*/
"prefer-h3": false,
"use-hosts": true,
"use-system-hosts": true,
/*
* DNS traffic follows Mihomo routing rules.
*/
"respect-rules": true,
/* ========================================================
* Fake-IP
* ======================================================== */
"enhanced-mode": "fake-ip",
"fake-ip-range": "198.18.0.1/16",
"fake-ip-filter-mode": "blacklist",
"fake-ip-filter": [
"*.lan",
"*.local",
"localhost",
"+.msftconnecttest.com",
"+.msftncsi.com",
"time.windows.com"
],
/* ========================================================
* Bootstrap DNS
*
* Used before the proxy connection is available.
* Must not depend on PRIVACY.
* ======================================================== */
"default-nameserver": [
"223.5.5.5",
"119.29.29.29"
],
/* ========================================================
* Proxy node domain resolution
*
* VERY IMPORTANT:
* Proxy server domains must be resolvable before
* the proxy itself is established.
* ======================================================== */
"proxy-server-nameserver": [
"223.5.5.5",
"119.29.29.29"
],
/* ========================================================
* DIRECT traffic DNS
* ======================================================== */
"direct-nameserver": [
"223.5.5.5",
"119.29.29.29"
],
"direct-nameserver-follow-policy": true,
/* ========================================================
* Split DNS
* ======================================================== */
"nameserver-policy": {
/*
* Mainland China domains:
*
* DNS query goes directly to China DNS.
*/
"geosite:cn": [
"223.5.5.5",
"119.29.29.29"
],
/*
* Overseas domains:
*
* DNS query itself goes through the manually
* selected PRIVACY proxy node.
*
* This prevents overseas DNS from going directly
* through the physical network.
*/
"geosite:geolocation-!cn": [
`https://cloudflare-dns.com/dns-query#${PRIVACY_GROUP}`,
`https://dns.google/dns-query#${PRIVACY_GROUP}`
]
},
/* ========================================================
* Default DNS
*
* Unknown / uncategorized domains use overseas DoH
* through PRIVACY.
* ======================================================== */
nameserver: [
`https://cloudflare-dns.com/dns-query#${PRIVACY_GROUP}`,
`https://dns.google/dns-query#${PRIVACY_GROUP}`
]
};
/* ==========================================================
* TUN
* ========================================================== */
config.tun = {
...(config.tun || {}),
enable: true,
/*
* Windows:
*
* Recommend SYSTEM first.
*
* It has better compatibility with Chromium QUIC/HTTP3
* on current Windows builds.
*/
stack: "system",
/*
* Automatically create routes.
*/
"auto-route": true,
/*
* Automatically detect physical outbound interface.
*/
"auto-detect-interface": true,
/*
* Reduce DNS / multi-homed routing leaks.
*/
"strict-route": true,
/*
* Hijack normal UDP/TCP port 53 DNS.
*/
"dns-hijack": [
"any:53",
"tcp://any:53"
]
};
/* ==========================================================
* Get subscription groups / proxies
* ========================================================== */
const oldGroups =
Array.isArray(config["proxy-groups"])
? config["proxy-groups"]
: [];
const proxies =
Array.isArray(config.proxies)
? config.proxies
: [];
const providers =
config["proxy-providers"] &&
typeof config["proxy-providers"] === "object"
? config["proxy-providers"]
: {};
if (
proxies.length === 0 &&
Object.keys(providers).length === 0
) {
throw new Error(
"没有找到代理节点或 proxy-provider"
);
}
/* ==========================================================
* Process old groups
* ========================================================== */
const processedGroups =
oldGroups
.filter((group) => {
return !(
group &&
group.name === PRIVACY_GROUP
);
})
.map((group) => {
if (
group &&
HIDDEN_GROUPS.has(group.name)
) {
return {
...group,
hidden: true
};
}
return group;
});
/* ==========================================================
* PRIVACY
*
* Manual selection only.
* ========================================================== */
const privacyGroup = {
name: PRIVACY_GROUP,
type: "select",
"include-all": true,
"exclude-filter": INFO_NODE_FILTER,
hidden: false
};
config["proxy-groups"] = [
privacyGroup,
...processedGroups
];
/* ==========================================================
* Routing rules
* ========================================================== */
config.rules = [
/* Loopback */
"IP-CIDR,127.0.0.0/8,DIRECT,no-resolve",
"IP-CIDR6,::1/128,DIRECT,no-resolve",
/* LAN / RFC1918 */
"IP-CIDR,10.0.0.0/8,DIRECT,no-resolve",
"IP-CIDR,172.16.0.0/12,DIRECT,no-resolve",
"IP-CIDR,192.168.0.0/16,DIRECT,no-resolve",
/* Link Local */
"IP-CIDR,169.254.0.0/16,DIRECT,no-resolve",
"IP-CIDR6,fe80::/10,DIRECT,no-resolve",
/* IPv6 ULA */
"IP-CIDR6,fc00::/7,DIRECT,no-resolve",
/* Multicast / Broadcast */
"IP-CIDR,224.0.0.0/4,DIRECT,no-resolve",
"IP-CIDR,255.255.255.255/32,DIRECT,no-resolve",
"IP-CIDR6,ff00::/8,DIRECT,no-resolve",
/* China domains */
"GEOSITE,cn,DIRECT",
/* China IP */
"GEOIP,CN,DIRECT",
/* Everything else */
`MATCH,${PRIVACY_GROUP}`
];
/* ==========================================================
* Debug
* ========================================================== */
console.info(
"========================================"
);
console.info(
"Mihomo Manual Privacy Routing"
);
console.info(
"Profile:",
profileName || ""
);
console.info(
"CN -> DIRECT"
);
console.info(
"Foreign -> PRIVACY"
);
console.info(
"DNS CN -> 223.5.5.5 / 119.29.29.29"
);
console.info(
"DNS Foreign -> Cloudflare / Google via PRIVACY"
);
console.info(
"TUN -> SYSTEM"
);
console.info(
"DNS Hijack -> ON"
);
console.info(
"Strict Route -> ON"
);
console.info(
"IPv6 -> OFF"
);
console.info(
"TCP Concurrent -> ON"
);
console.info(
"========================================"
);
return config;
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


暂无评论内容