Skip to content

Commit c10bc92

Browse files
committed
fix: 添加解析地址端口的功能,优化代理IP处理逻辑
1 parent 88e7eb0 commit c10bc92

1 file changed

Lines changed: 44 additions & 9 deletions

File tree

_worker.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ export default {
285285
} else if (new RegExp('/pyip=', 'i').test(url.pathname)) {
286286
proxyIP = url.pathname.toLowerCase().split('/pyip=')[1];
287287
enableSocks = false;
288+
} else if (new RegExp('/ip=', 'i').test(url.pathname)) {
289+
proxyIP = url.pathname.toLowerCase().split('/ip=')[1];
290+
enableSocks = false;
288291
}
289292

290293
return await 特洛伊OverWSHandler(request);
@@ -478,15 +481,7 @@ async function handleTCPOutBound(remoteSocket, addressRemote, portRemote, rawCli
478481
if (enableSocks) {
479482
tcpSocket2 = enableHttp ? await httpConnect(address, port) : await socks5Connect(address, port);
480483
} else {
481-
let 反代IP地址 = proxyIP, 反代IP端口 = 443;
482-
if (proxyIP.includes(']:')) {
483-
反代IP端口 = parseInt(proxyIP.split(']:')[1]) || 反代IP端口;
484-
反代IP地址 = proxyIP.split(']:')[0] + "]" || 反代IP地址;
485-
} else if (proxyIP.split(':').length === 2) {
486-
反代IP端口 = parseInt(proxyIP.split(':')[1]) || 反代IP端口;
487-
反代IP地址 = proxyIP.split(':')[0] || 反代IP地址;
488-
}
489-
if (proxyIP.toLowerCase().includes('.tp')) 反代IP端口 = parseInt(proxyIP.toLowerCase().split('.tp')[1].split('.')[0]) || 反代IP端口;
484+
const [反代IP地址, 反代IP端口] = await 解析地址端口(proxyIP);
490485
tcpSocket2 = connect({ hostname: 反代IP地址, port: 反代IP端口 });
491486
}
492487
}
@@ -5397,4 +5392,44 @@ function config_Html(token = "test", proxyhost = "") {
53975392
</html>`;
53985393

53995394
return html;
5395+
}
5396+
5397+
async function 解析地址端口(proxyIP) {
5398+
proxyIP = proxyIP.toLowerCase();
5399+
if (proxyIP.includes('.william')) {
5400+
const williamResult = await (async function 解析William域名(william) {
5401+
try {
5402+
const response = await fetch(`https://1.1.1.1/dns-query?name=${william}&type=TXT`, { headers: { 'Accept': 'application/dns-json' } });
5403+
if (!response.ok) return null;
5404+
const data = await response.json();
5405+
const txtRecords = (data.Answer || []).filter(record => record.type === 16).map(record => record.data);
5406+
if (txtRecords.length === 0) return null;
5407+
let txtData = txtRecords[0];
5408+
if (txtData.startsWith('"') && txtData.endsWith('"')) txtData = txtData.slice(1, -1);
5409+
const prefixes = txtData.replace(/\\010/g, ',').replace(/\n/g, ',').split(',').map(s => s.trim()).filter(Boolean);
5410+
if (prefixes.length === 0) return null;
5411+
return prefixes[Math.floor(Math.random() * prefixes.length)];
5412+
} catch (error) {
5413+
console.error('解析ProxyIP失败:', error);
5414+
return null;
5415+
}
5416+
})(proxyIP);
5417+
proxyIP = williamResult || proxyIP;
5418+
}
5419+
let 地址 = proxyIP, 端口 = 443;
5420+
if (proxyIP.includes('.tp')) {
5421+
const tpMatch = proxyIP.match(/\.tp(\d+)/);
5422+
if (tpMatch) 端口 = parseInt(tpMatch[1], 10);
5423+
return [地址, 端口];
5424+
}
5425+
if (proxyIP.includes(']:')) {
5426+
const parts = proxyIP.split(']:');
5427+
地址 = parts[0] + ']';
5428+
端口 = parseInt(parts[1], 10) || 端口;
5429+
} else if (proxyIP.includes(':') && !proxyIP.startsWith('[')) {
5430+
const colonIndex = proxyIP.lastIndexOf(':');
5431+
地址 = proxyIP.slice(0, colonIndex);
5432+
端口 = parseInt(proxyIP.slice(colonIndex + 1), 10) || 端口;
5433+
}
5434+
return [地址, 端口];
54005435
}

0 commit comments

Comments
 (0)