Skip to content

Commit 750e8dd

Browse files
committed
feat: 优化反代IP处理逻辑,支持逐个解析William域名的TXT记录
1 parent f7fc137 commit 750e8dd

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

_worker.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,31 +2153,30 @@ async function 解析地址端口(proxyIP, 目标域名 = 'dash.cloudflare.com',
21532153
return [地址, 端口];
21542154
}
21552155

2156+
const 反代IP数组 = await 整理成数组(proxyIP);
21562157
let 所有反代数组 = [];
21572158

2158-
if (proxyIP.includes('.william')) {
2159-
try {
2160-
let txtRecords = await DoH查询(proxyIP, 'TXT');
2161-
let txtData = txtRecords.filter(r => r.type === 16).map(r => /** @type {string} */(r.data));
2162-
if (txtData.length === 0) {
2163-
console.log(`[反代解析] 默认DoH未获取到TXT记录,切换Google DoH重试 ${proxyIP}`);
2164-
txtRecords = await DoH查询(proxyIP, 'TXT', 'https://dns.google/dns-query');
2165-
txtData = txtRecords.filter(r => r.type === 16).map(r => /** @type {string} */(r.data));
2166-
}
2167-
if (txtData.length > 0) {
2168-
let data = txtData[0];
2169-
if (data.startsWith('"') && data.endsWith('"')) data = data.slice(1, -1);
2170-
const prefixes = data.replace(/\\010/g, ',').replace(/\n/g, ',').split(',').map(s => s.trim()).filter(Boolean);
2171-
所有反代数组 = prefixes.map(prefix => 解析地址端口字符串(prefix));
2159+
// 遍历数组中的每个IP元素进行处理
2160+
for (const singleProxyIP of 反代IP数组) {
2161+
if (singleProxyIP.includes('.william')) {
2162+
try {
2163+
let txtRecords = await DoH查询(singleProxyIP, 'TXT');
2164+
let txtData = txtRecords.filter(r => r.type === 16).map(r => /** @type {string} */(r.data));
2165+
if (txtData.length === 0) {
2166+
console.log(`[反代解析] 默认DoH未获取到TXT记录,切换Google DoH重试 ${singleProxyIP}`);
2167+
txtRecords = await DoH查询(singleProxyIP, 'TXT', 'https://dns.google/dns-query');
2168+
txtData = txtRecords.filter(r => r.type === 16).map(r => /** @type {string} */(r.data));
2169+
}
2170+
if (txtData.length > 0) {
2171+
let data = txtData[0];
2172+
if (data.startsWith('"') && data.endsWith('"')) data = data.slice(1, -1);
2173+
const prefixes = data.replace(/\\010/g, ',').replace(/\n/g, ',').split(',').map(s => s.trim()).filter(Boolean);
2174+
所有反代数组.push(...prefixes.map(prefix => 解析地址端口字符串(prefix)));
2175+
}
2176+
} catch (error) {
2177+
console.error('解析William域名失败:', error);
21722178
}
2173-
} catch (error) {
2174-
console.error('解析William域名失败:', error);
2175-
}
2176-
} else {
2177-
const 反代IP数组 = await 整理成数组(proxyIP);
2178-
2179-
// 遍历数组中的每个IP元素进行处理
2180-
for (const singleProxyIP of 反代IP数组) {
2179+
} else {
21812180
let [地址, 端口] = 解析地址端口字符串(singleProxyIP);
21822181

21832182
if (singleProxyIP.includes('.tp')) {

0 commit comments

Comments
 (0)