fix: 更新SOCKS5可用性验证函数,增强错误信息中的代理参数显示

This commit is contained in:
cmliu
2025-11-07 02:37:00 +08:00
parent d3097e5dbb
commit 39b823d3df

View File

@@ -1201,9 +1201,11 @@ async function 解析地址端口(proxyIP) {
async function SOCKS5可用性验证(代理协议 = 'socks5', 代理参数) {
try { parsedSocks5Address = await 获取SOCKS5账号(代理参数); } catch (err) { return { success: false, error: err.message, proxy: 代理协议 + "://" + 代理参数 }; }
const { username, password, hostname, port } = parsedSocks5Address;
const 完整代理参数 = username && password ? `${username}:${password}@${hostname}:${port}` : `${hostname}:${port}`;
try {
const tcpSocket = 代理协议 == 'socks5' ? await socks5Connect('check.socks5.090227.xyz', 80) : await httpConnect('check.socks5.090227.xyz', 80);
if (!tcpSocket) return { success: false, error: '无法连接到代理服务器', proxy: 代理协议 + "://" + 代理参数 };
if (!tcpSocket) return { success: false, error: '无法连接到代理服务器', proxy: 代理协议 + "://" + 完整代理参数 };
try {
const writer = tcpSocket.writable.getWriter(), encoder = new TextEncoder();
await writer.write(encoder.encode(`GET /cdn-cgi/trace HTTP/1.1\r\nHost: check.socks5.090227.xyz\r\nConnection: close\r\n\r\n`));
@@ -1212,12 +1214,12 @@ async function SOCKS5可用性验证(代理协议 = 'socks5', 代理参数) {
let response = '';
try { while (true) { const { done, value } = await reader.read(); if (done) break; response += decoder.decode(value, { stream: true }); } } finally { reader.releaseLock(); }
await tcpSocket.close();
return { success: true, proxy: 代理协议 + "://" + 代理参数, ip: response.match(/ip=(.*)/)[1], loc: response.match(/loc=(.*)/)[1] };
return { success: true, proxy: 代理协议 + "://" + 完整代理参数, ip: response.match(/ip=(.*)/)[1], loc: response.match(/loc=(.*)/)[1] };
} catch (error) {
try { await tcpSocket.close(); } catch (e) { console.log('关闭连接时出错:', e); }
return { success: false, error: error.message, proxy: 代理协议 + "://" + 代理参数 };
return { success: false, error: error.message, proxy: 代理协议 + "://" + 完整代理参数 };
}
} catch (error) { return { success: false, error: error.message, proxy: 代理协议 + "://" + 代理参数 }; }
} catch (error) { return { success: false, error: error.message, proxy: 代理协议 + "://" + 完整代理参数 }; }
}
//////////////////////////////////////////////////////HTML伪装页面///////////////////////////////////////////////
async function nginx() {