diff --git a/Netch/Controllers/TUNTAPController.cs b/Netch/Controllers/TUNTAPController.cs index 5d390e8c..43189954 100644 --- a/Netch/Controllers/TUNTAPController.cs +++ b/Netch/Controllers/TUNTAPController.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Net; @@ -37,6 +38,9 @@ namespace Netch.Controllers /// public DNSController pDNSController = new DNSController(); + // ByPassLan IP + List BypassLanIPs = new List() { "10.0.0.0/8", "172.16.0.0/16", "192.168.0.0/24" }; + /// /// 配置 TUNTAP 适配器 /// @@ -101,6 +105,17 @@ namespace Netch.Controllers } } + foreach (var ip in BypassLanIPs) + { + var info = ip.Split('/'); + var address = IPAddress.Parse(info[0]); + + if (!IPAddress.IsLoopback(address)) + { + NativeMethods.CreateRoute(address.ToString(), int.Parse(info[1]), Global.Adapter.Gateway.ToString(), Global.Adapter.Index); + } + } + if (SavedMode.Type == 2) // 处理仅规则内走直连 { // 将 TUN/TAP 网卡权重放到最高 @@ -158,7 +173,7 @@ namespace Netch.Controllers } } //处理NAT类型检测,由于协议的原因,无法仅通过域名确定需要代理的IP,自己记录解析了返回的IP,仅支持默认检测服务器 - if(Global.Settings.STUN_Server == "stun.stunprotocol.org") + if (Global.Settings.STUN_Server == "stun.stunprotocol.org") { try { @@ -167,7 +182,7 @@ namespace Netch.Controllers { NativeMethods.CreateRoute(nttAddress.ToString(), prefix, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index); } - var nttrAddress= Dns.GetHostAddresses("stunresponse.coldthunder11.com")[0]; + var nttrAddress = Dns.GetHostAddresses("stunresponse.coldthunder11.com")[0]; if (int.TryParse("32", out var prefixr)) { NativeMethods.CreateRoute(nttrAddress.ToString(), prefixr, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index); @@ -301,6 +316,16 @@ namespace Netch.Controllers NativeMethods.DeleteRoute(address.ToString(), int.Parse(info[1]), Global.Adapter.Gateway.ToString(), Global.Adapter.Index); } } + foreach (var ip in BypassLanIPs) + { + var info = ip.Split('/'); + var address = IPAddress.Parse(info[0]); + + if (!IPAddress.IsLoopback(address)) + { + NativeMethods.DeleteRoute(address.ToString(), int.Parse(info[1]), Global.Adapter.Gateway.ToString(), Global.Adapter.Index); + } + } if (SavedMode.BypassChina) { @@ -402,7 +427,7 @@ namespace Netch.Controllers else { Instance.StartInfo.Arguments = string.Format("-proxyServer 127.0.0.1:{0} -tunAddr {1} -tunMask {2} -tunGw {3} -tunDns {4} -tunName \"{5}\"", Global.Settings.Socks5LocalPort, Global.Settings.TUNTAP.Address, Global.Settings.TUNTAP.Netmask, Global.Settings.TUNTAP.Gateway, dns, adapterName); - } + } Instance.StartInfo.CreateNoWindow = true; Instance.StartInfo.RedirectStandardError = true; diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index 6d25ca94..9a85e998 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -174,6 +174,7 @@ this.TUNTAPUseCustomDNSCheckBox.TabIndex = 9; this.TUNTAPUseCustomDNSCheckBox.Text = "Use Custom DNS"; this.TUNTAPUseCustomDNSCheckBox.UseVisualStyleBackColor = true; + this.TUNTAPUseCustomDNSCheckBox.CheckedChanged += new System.EventHandler(this.TUNTAPUseCustomDNSCheckBox_CheckedChanged); // // TUNTAPDNSLabel // diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index 979001c6..b66d25e6 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -132,7 +132,7 @@ namespace Netch.Models /// /// 全局绕过 IP 列表 /// - public List BypassIPs = new List() { "10.0.0.0/8", "172.16.0.0/16", "192.168.0.0/24" }; + public List BypassIPs = new List(); /// /// 已保存的快捷配置 diff --git a/binaries b/binaries index 42d2225c..4218a905 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit 42d2225c723a7a2fa2b3e15126c69c84c1eca326 +Subproject commit 4218a90538491dc9f41e4bdd870d9f5191bf74bc