Skip to content

Commit 0bd1389

Browse files
authored
Merge pull request shadowsocks#2049 from studentmain/master
Keep user bypass setting when use global proxy mode
2 parents 91f0bf6 + a63dec8 commit 0bd1389

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

shadowsocks-csharp/Util/SystemProxy/Sysproxy.cs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
using Shadowsocks.Model;
44
using Shadowsocks.Properties;
55
using System;
6+
using System.Collections.Generic;
67
using System.Diagnostics;
78
using System.IO;
9+
using System.Linq;
810
using System.Text;
911
using System.Threading;
1012

@@ -14,6 +16,31 @@ public static class Sysproxy
1416
{
1517
private const string _userWininetConfigFile = "user-wininet.json";
1618

19+
private static string[] _lanIP = {
20+
"<local>",
21+
"localhost",
22+
"127.*",
23+
"10.*",
24+
"172.16.*",
25+
"172.17.*",
26+
"172.18.*",
27+
"172.19.*",
28+
"172.20.*",
29+
"172.21.*",
30+
"172.22.*",
31+
"172.23.*",
32+
"172.24.*",
33+
"172.25.*",
34+
"172.26.*",
35+
"172.27.*",
36+
"172.28.*",
37+
"172.29.*",
38+
"172.30.*",
39+
"172.31.*",
40+
"192.168.*"
41+
};
42+
43+
1744
private static string _queryStr;
1845

1946
// In general, this won't change
@@ -61,8 +88,13 @@ public static void SetIEProxy(bool enable, bool global, string proxyServer, stri
6188
string arguments;
6289
if (enable)
6390
{
91+
List<string> customBypass = new List<string>(_userSettings.BypassList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
92+
customBypass.AddRange(_lanIP);
93+
string[] realBypassStrings = customBypass.Distinct().ToArray();
94+
string realBypassString = string.Join(";", realBypassStrings);
95+
6496
arguments = global
65-
? $"global {proxyServer} <local>;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.*"
97+
? $"global {proxyServer} {realBypassString}"
6698
: $"pac {pacURL}";
6799
}
68100
else
@@ -88,11 +120,11 @@ public static bool ResetIEProxy()
88120
{
89121
try
90122
{
91-
// clear user-wininet.json
92-
_userSettings = new SysproxyConfig();
93-
Save();
94-
// clear system setting
95-
ExecSysproxy("set 1 - - -");
123+
// clear user-wininet.json
124+
_userSettings = new SysproxyConfig();
125+
Save();
126+
// clear system setting
127+
ExecSysproxy("set 1 - - -");
96128
}
97129
catch (Exception e)
98130
{

0 commit comments

Comments
 (0)