Files
seabox_fanyi_application/fix_proxy_ip.js
2025-09-18 15:14:14 +08:00

160 lines
5.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 修复代理IP地址脚本
// 将被截断的IP地址 143.20.228.19 修复为 143.20.228.192
const { app } = require('electron');
async function fixProxyIP() {
console.log('🔧 修复代理IP地址...\n');
try {
// 查找所有包含错误IP的代理配置
const allConfigs = await app.sdb.selectAll("proxy_config");
console.log('📋 当前所有代理配置:');
let foundIncorrectIP = false;
for (const config of allConfigs) {
console.log(`配置ID ${config.id}:`);
console.log(` partitionId: ${config.partitionId}`);
console.log(` proxyIp: ${config.proxyIp}`);
console.log(` proxyPort: ${config.proxyPort}`);
console.log(` proxyStatus: ${config.proxyStatus}`);
// 检查是否是被截断的IP
if (config.proxyIp === '143.20.228.19') {
foundIncorrectIP = true;
console.log(` ❌ 发现被截断的IP地址: ${config.proxyIp}`);
// 修复IP地址
await app.sdb.update("proxy_config", {
proxyIp: "143.20.228.192"
}, { id: config.id });
console.log(` ✅ 已修复为: 143.20.228.192`);
} else if (config.proxyIp === '143.20.228.192') {
console.log(` ✅ IP地址正确: ${config.proxyIp}`);
}
console.log('');
}
if (!foundIncorrectIP) {
console.log('✅ 未发现需要修复的IP地址');
}
// 检查全局代理配置
const globalConfig = await app.sdb.selectOne("global_proxy_config");
if (globalConfig && globalConfig.proxyIp === '143.20.228.19') {
console.log('🔧 修复全局代理配置中的IP地址...');
await app.sdb.update("global_proxy_config", {
proxyIp: "143.20.228.192"
});
console.log('✅ 全局代理IP地址已修复');
}
console.log('\n🎯 修复完成!请重新测试代理连接。');
} catch (error) {
console.error('❌ 修复代理IP地址失败:', error);
}
}
async function verifyProxyConfig() {
console.log('🔍 验证代理配置...\n');
try {
const allConfigs = await app.sdb.selectAll("proxy_config");
for (const config of allConfigs) {
if (config.proxyStatus === 'true') {
console.log(`✅ 活动代理配置 (ID: ${config.id}):`);
console.log(` partitionId: ${config.partitionId}`);
console.log(` 类型: ${config.proxyType}`);
console.log(` 地址: ${config.proxyIp}:${config.proxyPort}`);
console.log(` 认证: ${config.userVerifyStatus === 'true' ? '启用' : '禁用'}`);
console.log(` 用户名: ${config.username || '未设置'}`);
console.log(` 密码: ${config.password ? '已设置' : '未设置'}`);
// 验证IP格式
const ipPattern = /^(\d{1,3}\.){3}\d{1,3}$/;
if (!ipPattern.test(config.proxyIp)) {
console.log(` ❌ IP地址格式无效: ${config.proxyIp}`);
} else {
console.log(` ✅ IP地址格式正确`);
}
// 验证端口
const port = parseInt(config.proxyPort);
if (isNaN(port) || port < 1 || port > 65535) {
console.log(` ❌ 端口号无效: ${config.proxyPort}`);
} else {
console.log(` ✅ 端口号正确`);
}
console.log('');
}
}
} catch (error) {
console.error('❌ 验证代理配置失败:', error);
}
}
async function setCorrectProxyConfig(partitionId) {
console.log(`🔧 为 ${partitionId} 设置正确的代理配置...\n`);
const correctConfig = {
proxyStatus: "true",
proxyType: "socks5", // 改为SOCKS5通常更稳定
proxyIp: "143.20.228.192", // 完整的IP地址
proxyPort: "3306",
userVerifyStatus: "true",
username: "mNrz1aEg",
password: "3xV3dBYB"
};
try {
const existingConfig = await app.sdb.selectOne("proxy_config", { partitionId });
if (existingConfig) {
await app.sdb.update("proxy_config", correctConfig, { id: existingConfig.id });
console.log('✅ 代理配置已更新');
} else {
await app.sdb.insert("proxy_config", { partitionId, ...correctConfig });
console.log('✅ 代理配置已创建');
}
console.log('📋 新配置详情:');
console.log(` 类型: ${correctConfig.proxyType.toUpperCase()}`);
console.log(` 地址: ${correctConfig.proxyIp}:${correctConfig.proxyPort}`);
console.log(` 认证: ${correctConfig.userVerifyStatus === 'true' ? '启用' : '禁用'}`);
console.log(` 用户名: ${correctConfig.username}`);
console.log(` 密码: ${'*'.repeat(correctConfig.password.length)}`);
} catch (error) {
console.error('❌ 设置代理配置失败:', error);
}
}
// 导出函数
module.exports = {
fixProxyIP,
verifyProxyConfig,
setCorrectProxyConfig
};
// 如果直接运行此文件
if (require.main === module) {
console.log('⚠️ 这个脚本需要在Electron应用启动后调用');
console.log('💡 请在应用的控制台中运行以下命令:');
console.log('');
console.log(' // 修复被截断的IP地址');
console.log(' const fix = require("./fix_proxy_ip.js");');
console.log(' fix.fixProxyIP();');
console.log('');
console.log(' // 验证代理配置');
console.log(' fix.verifyProxyConfig();');
console.log('');
console.log(' // 为特定会话设置正确配置替换为实际的partitionId');
console.log(' fix.setCorrectProxyConfig("sB4yuENS");');
}