@@ -216,6 +216,10 @@ def run(self):
216216 cmd .extend (['-dns' , self .config ['dns' ]])
217217 if self .config .get ('ech' ) and self .config ['ech' ] != 'cloudflare-ech.com' :
218218 cmd .extend (['-ech' , self .config ['ech' ]])
219+ # 添加分流模式参数
220+ routing_mode = self .config .get ('routing_mode' , 'bypass_cn' )
221+ if routing_mode :
222+ cmd .extend (['-routing' , routing_mode ])
219223
220224 try :
221225 # Windows 上需要指定 UTF-8 编码,因为 Go 程序输出 UTF-8
@@ -1227,6 +1231,7 @@ def _set_system_proxy(self, enabled):
12271231 # 获取当前监听地址
12281232 listen = self .listen_edit .text ()
12291233 if not listen and enabled :
1234+ self .append_log ("[系统] 监听地址为空,无法设置系统代理\n " )
12301235 return False
12311236
12321237 # 获取分流模式
@@ -1240,6 +1245,9 @@ def _set_system_proxy(self, enabled):
12401245 self .append_log ("[系统] 分流模式为\" 不改变代理\" ,跳过系统代理设置\n " )
12411246 return True
12421247
1248+ # 注意:分流功能已在 Go 程序中实现,系统代理只需设置为全局代理
1249+ # Go 程序会根据 -routing 参数自动处理分流
1250+
12431251 if sys .platform == 'win32' :
12441252 return self ._set_windows_proxy (enabled , listen , routing_mode )
12451253 elif sys .platform == 'darwin' :
@@ -1249,56 +1257,17 @@ def _set_system_proxy(self, enabled):
12491257 return False
12501258 except Exception as e :
12511259 self .append_log (f"[系统] 设置系统代理失败: { e } \n " )
1260+ import traceback
1261+ self .append_log (f"[系统] 错误详情: { traceback .format_exc ()} \n " )
12521262 return False
12531263
12541264 def _get_proxy_bypass_list (self , routing_mode ):
1255- """获取代理绕过列表"""
1265+ """获取代理绕过列表(分流已在 Go 程序中实现,这里只设置本地和内网绕过) """
12561266 # 基础绕过列表(本地和内网)
1267+ # 注意:分流功能已在 Go 程序中实现,系统代理设置为全局代理
1268+ # Go 程序会根据分流模式自动决定哪些流量走代理,哪些直连
12571269 base_bypass = "localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*;<local>"
1258-
1259- if routing_mode == 'global' :
1260- # 全局代理:只绕过本地和内网
1261- return base_bypass
1262- elif routing_mode == 'bypass_cn' :
1263- # 跳过中国大陆:添加中国IP段和常见中国域名
1264- cn_domains = [
1265- "*.cn" , "*.com.cn" , "*.net.cn" , "*.org.cn" , "*.gov.cn" , "*.edu.cn" ,
1266- "*.baidu.com" , "*.qq.com" , "*.taobao.com" , "*.tmall.com" , "*.alipay.com" ,
1267- "*.weibo.com" , "*.sina.com" , "*.163.com" , "*.126.com" , "*.sohu.com" ,
1268- "*.youku.com" , "*.iqiyi.com" , "*.bilibili.com" , "*.douyin.com" , "*.douban.com" ,
1269- "*.zhihu.com" , "*.jd.com" , "*.alibaba.com" , "*.1688.com" ,
1270- "*.tencent.com" , "*.weixin.qq.com" , "*.qzone.com"
1271- ]
1272-
1273- # 使用下载的中国IP列表
1274- cn_ip_wildcards = []
1275- if self .china_ip_ranges :
1276- cn_ip_wildcards = self ._convert_ip_ranges_to_wildcards (self .china_ip_ranges )
1277- else :
1278- # 如果还没加载完成,使用默认的主要IP段
1279- cn_ip_wildcards = [
1280- "1.*" , "14.*" , "27.*" , "36.*" , "39.*" , "42.*" , "49.*" , "58.*" , "59.*" , "60.*" ,
1281- "61.*" , "101.*" , "103.*" , "106.*" , "110.*" , "111.*" , "112.*" , "113.*" , "114.*" , "115.*" ,
1282- "116.*" , "117.*" , "118.*" , "119.*" , "120.*" , "121.*" , "122.*" , "123.*" , "124.*" , "125.*" ,
1283- "171.*" , "175.*" , "180.*" , "182.*" , "183.*" , "202.*" , "203.*" , "210.*" , "211.*" , "218.*" ,
1284- "219.*" , "220.*" , "221.*" , "222.*" , "223.*"
1285- ]
1286-
1287- # Windows ProxyOverride 使用分号分隔,支持通配符
1288- # 注意:Windows ProxyOverride 有长度限制(约2048字符),需要优化
1289- cn_bypass_parts = cn_domains + cn_ip_wildcards
1290- cn_bypass = ";" .join (cn_bypass_parts )
1291-
1292- # 如果超过长度限制,只使用域名和主要IP段
1293- MAX_LENGTH = 2000
1294- if len (cn_bypass ) > MAX_LENGTH :
1295- # 只使用域名和A段通配符(格式:A.*)
1296- a_segment_wildcards = [w for w in cn_ip_wildcards if w .count ('.' ) == 1 and w .endswith ('.*' )]
1297- cn_bypass = ";" .join (cn_domains + a_segment_wildcards )
1298-
1299- return f"{ base_bypass } ;{ cn_bypass } "
1300- else :
1301- return base_bypass
1270+ return base_bypass
13021271
13031272 def _set_windows_proxy (self , enabled , listen , routing_mode ):
13041273 """设置 Windows 系统代理"""
@@ -1321,7 +1290,9 @@ def _set_windows_proxy(self, enabled, listen, routing_mode):
13211290 winreg .SetValueEx (key , "ProxyEnable" , 0 , winreg .REG_DWORD , 1 )
13221291 # 根据分流模式设置绕过列表
13231292 bypass_list = self ._get_proxy_bypass_list (routing_mode )
1293+ self .append_log (f"[系统] 设置绕过列表,长度: { len (bypass_list )} 字符\n " )
13241294 winreg .SetValueEx (key , "ProxyOverride" , 0 , winreg .REG_SZ , bypass_list )
1295+ self .append_log (f"[系统] Windows 代理已设置: { proxy_server } , 分流模式: { routing_mode } \n " )
13251296 else :
13261297 # 关闭代理
13271298 winreg .SetValueEx (key , "ProxyEnable" , 0 , winreg .REG_DWORD , 0 )
@@ -1344,46 +1315,17 @@ def _set_windows_proxy(self, enabled, listen, routing_mode):
13441315 return False
13451316
13461317 def _get_macos_bypass_list (self , routing_mode ):
1347- """获取 macOS 代理绕过列表"""
1318+ """获取 macOS 代理绕过列表(分流已在 Go 程序中实现,这里只设置本地和内网绕过) """
13481319 # 基础绕过列表(本地和内网)
1320+ # 注意:分流功能已在 Go 程序中实现,系统代理设置为全局代理
1321+ # Go 程序会根据分流模式自动决定哪些流量走代理,哪些直连
13491322 base_bypass = [
13501323 "localhost" , "127.*" , "10.*" , "172.16.*" , "172.17.*" , "172.18.*" ,
13511324 "172.19.*" , "172.20.*" , "172.21.*" , "172.22.*" , "172.23.*" , "172.24.*" ,
13521325 "172.25.*" , "172.26.*" , "172.27.*" , "172.28.*" , "172.29.*" , "172.30.*" ,
13531326 "172.31.*" , "192.168.*" , "*.local" , "169.254.*"
13541327 ]
1355-
1356- if routing_mode == 'global' :
1357- # 全局代理:只绕过本地和内网
1358- return base_bypass
1359- elif routing_mode == 'bypass_cn' :
1360- # 跳过中国大陆:添加中国域名和IP
1361- cn_domains = [
1362- "*.cn" , "*.com.cn" , "*.net.cn" , "*.org.cn" , "*.gov.cn" , "*.edu.cn" ,
1363- "*.baidu.com" , "*.qq.com" , "*.taobao.com" , "*.tmall.com" , "*.alipay.com" ,
1364- "*.weibo.com" , "*.sina.com" , "*.163.com" , "*.126.com" , "*.sohu.com" ,
1365- "*.youku.com" , "*.iqiyi.com" , "*.bilibili.com" , "*.douyin.com" , "*.douban.com" ,
1366- "*.zhihu.com" , "*.jd.com" , "*.alibaba.com" , "*.1688.com" ,
1367- "*.tencent.com" , "*.weixin.qq.com" , "*.qzone.com"
1368- ]
1369-
1370- # 使用下载的中国IP列表(macOS也支持IP通配符)
1371- cn_ip_wildcards = []
1372- if self .china_ip_ranges :
1373- cn_ip_wildcards = self ._convert_ip_ranges_to_wildcards (self .china_ip_ranges )
1374- else :
1375- # 如果还没加载完成,使用默认的主要IP段
1376- cn_ip_wildcards = [
1377- "1.*" , "14.*" , "27.*" , "36.*" , "39.*" , "42.*" , "49.*" , "58.*" , "59.*" , "60.*" ,
1378- "61.*" , "101.*" , "103.*" , "106.*" , "110.*" , "111.*" , "112.*" , "113.*" , "114.*" , "115.*" ,
1379- "116.*" , "117.*" , "118.*" , "119.*" , "120.*" , "121.*" , "122.*" , "123.*" , "124.*" , "125.*" ,
1380- "171.*" , "175.*" , "180.*" , "182.*" , "183.*" , "202.*" , "203.*" , "210.*" , "211.*" , "218.*" ,
1381- "219.*" , "220.*" , "221.*" , "222.*" , "223.*"
1382- ]
1383-
1384- return base_bypass + cn_domains + cn_ip_wildcards
1385- else :
1386- return base_bypass
1328+ return base_bypass
13871329
13881330 def _set_macos_proxy (self , enabled , listen , routing_mode ):
13891331 """设置 macOS 系统代理"""
0 commit comments