Skip to content

Commit

Permalink
Keep user bypass setting when use global proxy mode
Browse files Browse the repository at this point in the history
  • Loading branch information
StudentEx committed Oct 18, 2018
1 parent 91f0bf6 commit a63dec8
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions shadowsocks-csharp/Util/SystemProxy/Sysproxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using Shadowsocks.Model;
using Shadowsocks.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

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

private static string[] _lanIP = {
"<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.*"
};


private static string _queryStr;

// In general, this won't change
Expand Down Expand Up @@ -61,8 +88,13 @@ public static void SetIEProxy(bool enable, bool global, string proxyServer, stri
string arguments;
if (enable)
{
List<string> customBypass = new List<string>(_userSettings.BypassList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
customBypass.AddRange(_lanIP);
string[] realBypassStrings = customBypass.Distinct().ToArray();
string realBypassString = string.Join(";", realBypassStrings);

arguments = global
? $"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.*"
? $"global {proxyServer} {realBypassString}"
: $"pac {pacURL}";
}
else
Expand All @@ -88,11 +120,11 @@ public static bool ResetIEProxy()
{
try
{
// clear user-wininet.json
_userSettings = new SysproxyConfig();
Save();
// clear system setting
ExecSysproxy("set 1 - - -");
// clear user-wininet.json
_userSettings = new SysproxyConfig();
Save();
// clear system setting
ExecSysproxy("set 1 - - -");
}
catch (Exception e)
{
Expand Down

0 comments on commit a63dec8

Please sign in to comment.