From 725fdc2e9aab39c0e1af921b7ccad281839b815e Mon Sep 17 00:00:00 2001 From: ColdThunder11 Date: Thu, 12 Mar 2020 15:29:34 +0800 Subject: [PATCH] Support DNS proxy and NAT type test in mode2 --- Netch/Controllers/TUNTAPController.cs | 91 +++++++++++++ Netch/Forms/SettingForm.Designer.cs | 179 ++++++++++++++++---------- Netch/Forms/SettingForm.cs | 4 + Netch/Models/Setting.cs | 5 + Netch/Resources/zh-CN | 1 + 5 files changed, 214 insertions(+), 66 deletions(-) diff --git a/Netch/Controllers/TUNTAPController.cs b/Netch/Controllers/TUNTAPController.cs index 6fd5fd0a..5d390e8c 100644 --- a/Netch/Controllers/TUNTAPController.cs +++ b/Netch/Controllers/TUNTAPController.cs @@ -157,6 +157,54 @@ namespace Netch.Controllers } } } + //处理NAT类型检测,由于协议的原因,无法仅通过域名确定需要代理的IP,自己记录解析了返回的IP,仅支持默认检测服务器 + if(Global.Settings.STUN_Server == "stun.stunprotocol.org") + { + try + { + var nttAddress = Dns.GetHostAddresses(Global.Settings.STUN_Server)[0]; + if (int.TryParse("32", out var prefix)) + { + NativeMethods.CreateRoute(nttAddress.ToString(), prefix, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index); + } + 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); + } + } + catch + { + Logging.Info("NAT类型测试域名解析失败,将不会被添加到代理列表。"); + } + } + //处理DNS代理 + if (Global.Settings.TUNTAP.ProxyDNS) + { + if (Global.Settings.TUNTAP.UseCustomDNS) + { + string dns = ""; + foreach (var value in Global.Settings.TUNTAP.DNS) + { + dns += value; + dns += ','; + } + + dns = dns.Trim(); + dns = dns.Substring(0, dns.Length - 1); + if (int.TryParse("32", out var prefix)) + { + NativeMethods.CreateRoute(dns, prefix, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index); + } + } + else + { + if (int.TryParse("32", out var prefix)) + { + NativeMethods.CreateRoute("1.1.1.1", prefix, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index); + } + } + } } return true; } @@ -198,6 +246,49 @@ namespace Netch.Controllers } } } + if (Global.Settings.STUN_Server == "stun.stunprotocol.org") + { + try + { + var nttAddress = Dns.GetHostAddresses(Global.Settings.STUN_Server)[0]; + if (int.TryParse("32", out var prefix)) + { + NativeMethods.DeleteRoute(nttAddress.ToString(), prefix, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index); + } + var nttrAddress = Dns.GetHostAddresses("stunresponse.coldthunder11.com")[0]; + if (int.TryParse("32", out var prefixr)) + { + NativeMethods.DeleteRoute(nttrAddress.ToString(), prefixr, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index); + } + } + catch { } + } + if (Global.Settings.TUNTAP.ProxyDNS) + { + if (Global.Settings.TUNTAP.UseCustomDNS) + { + string dns = ""; + foreach (var value in Global.Settings.TUNTAP.DNS) + { + dns += value; + dns += ','; + } + + dns = dns.Trim(); + dns = dns.Substring(0, dns.Length - 1); + if (int.TryParse("32", out var prefix)) + { + NativeMethods.DeleteRoute(dns, prefix, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index); + } + } + else + { + if (int.TryParse("32", out var prefix)) + { + NativeMethods.DeleteRoute("1.1.1.1", prefix, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index); + } + } + } } foreach (var ip in Global.Settings.BypassIPs) diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index 4d8b6bb2..6d25ca94 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -36,6 +36,7 @@ this.Socks5PortLabel = new System.Windows.Forms.Label(); this.Socks5PortTextBox = new System.Windows.Forms.TextBox(); this.TUNTAPGroupBox = new System.Windows.Forms.GroupBox(); + this.TUNTAPProxyDNSCheckBox = new System.Windows.Forms.CheckBox(); this.TUNTAPUseCustomDNSCheckBox = new System.Windows.Forms.CheckBox(); this.TUNTAPDNSLabel = new System.Windows.Forms.Label(); this.TUNTAPDNSTextBox = new System.Windows.Forms.TextBox(); @@ -72,9 +73,11 @@ this.PortGroupBox.Controls.Add(this.HTTPPortTextBox); this.PortGroupBox.Controls.Add(this.Socks5PortLabel); this.PortGroupBox.Controls.Add(this.Socks5PortTextBox); - this.PortGroupBox.Location = new System.Drawing.Point(12, 12); + this.PortGroupBox.Location = new System.Drawing.Point(18, 18); + this.PortGroupBox.Margin = new System.Windows.Forms.Padding(4); this.PortGroupBox.Name = "PortGroupBox"; - this.PortGroupBox.Size = new System.Drawing.Size(420, 140); + this.PortGroupBox.Padding = new System.Windows.Forms.Padding(4); + this.PortGroupBox.Size = new System.Drawing.Size(630, 210); this.PortGroupBox.TabIndex = 0; this.PortGroupBox.TabStop = false; this.PortGroupBox.Text = "Local Port"; @@ -82,9 +85,10 @@ // AllowDevicesCheckBox // this.AllowDevicesCheckBox.AutoSize = true; - this.AllowDevicesCheckBox.Location = new System.Drawing.Point(120, 80); + this.AllowDevicesCheckBox.Location = new System.Drawing.Point(180, 120); + this.AllowDevicesCheckBox.Margin = new System.Windows.Forms.Padding(4); this.AllowDevicesCheckBox.Name = "AllowDevicesCheckBox"; - this.AllowDevicesCheckBox.Size = new System.Drawing.Size(206, 21); + this.AllowDevicesCheckBox.Size = new System.Drawing.Size(301, 28); this.AllowDevicesCheckBox.TabIndex = 5; this.AllowDevicesCheckBox.Text = "Allow other Devices to connect"; this.AllowDevicesCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -93,39 +97,44 @@ // HTTPPortLabel // this.HTTPPortLabel.AutoSize = true; - this.HTTPPortLabel.Location = new System.Drawing.Point(9, 54); + this.HTTPPortLabel.Location = new System.Drawing.Point(14, 81); + this.HTTPPortLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.HTTPPortLabel.Name = "HTTPPortLabel"; - this.HTTPPortLabel.Size = new System.Drawing.Size(38, 17); + this.HTTPPortLabel.Size = new System.Drawing.Size(55, 24); this.HTTPPortLabel.TabIndex = 3; this.HTTPPortLabel.Text = "HTTP"; // // HTTPPortTextBox // - this.HTTPPortTextBox.Location = new System.Drawing.Point(120, 51); + this.HTTPPortTextBox.Location = new System.Drawing.Point(180, 76); + this.HTTPPortTextBox.Margin = new System.Windows.Forms.Padding(4); this.HTTPPortTextBox.Name = "HTTPPortTextBox"; - this.HTTPPortTextBox.Size = new System.Drawing.Size(294, 23); + this.HTTPPortTextBox.Size = new System.Drawing.Size(439, 31); this.HTTPPortTextBox.TabIndex = 4; this.HTTPPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // Socks5PortLabel // this.Socks5PortLabel.AutoSize = true; - this.Socks5PortLabel.Location = new System.Drawing.Point(9, 25); + this.Socks5PortLabel.Location = new System.Drawing.Point(14, 38); + this.Socks5PortLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.Socks5PortLabel.Name = "Socks5PortLabel"; - this.Socks5PortLabel.Size = new System.Drawing.Size(49, 17); + this.Socks5PortLabel.Size = new System.Drawing.Size(69, 24); this.Socks5PortLabel.TabIndex = 0; this.Socks5PortLabel.Text = "Socks5"; // // Socks5PortTextBox // - this.Socks5PortTextBox.Location = new System.Drawing.Point(120, 22); + this.Socks5PortTextBox.Location = new System.Drawing.Point(180, 33); + this.Socks5PortTextBox.Margin = new System.Windows.Forms.Padding(4); this.Socks5PortTextBox.Name = "Socks5PortTextBox"; - this.Socks5PortTextBox.Size = new System.Drawing.Size(294, 23); + this.Socks5PortTextBox.Size = new System.Drawing.Size(439, 31); this.Socks5PortTextBox.TabIndex = 1; this.Socks5PortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // TUNTAPGroupBox // + this.TUNTAPGroupBox.Controls.Add(this.TUNTAPProxyDNSCheckBox); this.TUNTAPGroupBox.Controls.Add(this.TUNTAPUseCustomDNSCheckBox); this.TUNTAPGroupBox.Controls.Add(this.TUNTAPDNSLabel); this.TUNTAPGroupBox.Controls.Add(this.TUNTAPDNSTextBox); @@ -135,98 +144,120 @@ this.TUNTAPGroupBox.Controls.Add(this.TUNTAPNetmaskTextBox); this.TUNTAPGroupBox.Controls.Add(this.TUNTAPAddressLabel); this.TUNTAPGroupBox.Controls.Add(this.TUNTAPAddressTextBox); - this.TUNTAPGroupBox.Location = new System.Drawing.Point(12, 158); + this.TUNTAPGroupBox.Location = new System.Drawing.Point(18, 237); + this.TUNTAPGroupBox.Margin = new System.Windows.Forms.Padding(4); this.TUNTAPGroupBox.Name = "TUNTAPGroupBox"; - this.TUNTAPGroupBox.Size = new System.Drawing.Size(420, 164); + this.TUNTAPGroupBox.Padding = new System.Windows.Forms.Padding(4); + this.TUNTAPGroupBox.Size = new System.Drawing.Size(630, 281); this.TUNTAPGroupBox.TabIndex = 3; this.TUNTAPGroupBox.TabStop = false; this.TUNTAPGroupBox.Text = "TUN/TAP"; // + // TUNTAPProxyDNSCheckBox + // + this.TUNTAPProxyDNSCheckBox.AutoSize = true; + this.TUNTAPProxyDNSCheckBox.Location = new System.Drawing.Point(180, 243); + this.TUNTAPProxyDNSCheckBox.Margin = new System.Windows.Forms.Padding(4); + this.TUNTAPProxyDNSCheckBox.Name = "TUNTAPProxyDNSCheckBox"; + this.TUNTAPProxyDNSCheckBox.Size = new System.Drawing.Size(221, 28); + this.TUNTAPProxyDNSCheckBox.TabIndex = 10; + this.TUNTAPProxyDNSCheckBox.Text = "Proxy DNS in Mode 2"; + this.TUNTAPProxyDNSCheckBox.UseVisualStyleBackColor = true; + // // TUNTAPUseCustomDNSCheckBox // this.TUNTAPUseCustomDNSCheckBox.AutoSize = true; - this.TUNTAPUseCustomDNSCheckBox.Location = new System.Drawing.Point(120, 138); + this.TUNTAPUseCustomDNSCheckBox.Location = new System.Drawing.Point(180, 207); + this.TUNTAPUseCustomDNSCheckBox.Margin = new System.Windows.Forms.Padding(4); this.TUNTAPUseCustomDNSCheckBox.Name = "TUNTAPUseCustomDNSCheckBox"; - this.TUNTAPUseCustomDNSCheckBox.Size = new System.Drawing.Size(127, 21); + this.TUNTAPUseCustomDNSCheckBox.Size = new System.Drawing.Size(182, 28); this.TUNTAPUseCustomDNSCheckBox.TabIndex = 9; this.TUNTAPUseCustomDNSCheckBox.Text = "Use Custom DNS"; this.TUNTAPUseCustomDNSCheckBox.UseVisualStyleBackColor = true; - this.TUNTAPUseCustomDNSCheckBox.CheckedChanged += new System.EventHandler(this.TUNTAPUseCustomDNSCheckBox_CheckedChanged); // // TUNTAPDNSLabel // this.TUNTAPDNSLabel.AutoSize = true; - this.TUNTAPDNSLabel.Location = new System.Drawing.Point(9, 112); + this.TUNTAPDNSLabel.Location = new System.Drawing.Point(14, 168); + this.TUNTAPDNSLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.TUNTAPDNSLabel.Name = "TUNTAPDNSLabel"; - this.TUNTAPDNSLabel.Size = new System.Drawing.Size(34, 17); + this.TUNTAPDNSLabel.Size = new System.Drawing.Size(49, 24); this.TUNTAPDNSLabel.TabIndex = 7; this.TUNTAPDNSLabel.Text = "DNS"; // // TUNTAPDNSTextBox // - this.TUNTAPDNSTextBox.Location = new System.Drawing.Point(120, 110); + this.TUNTAPDNSTextBox.Location = new System.Drawing.Point(180, 165); + this.TUNTAPDNSTextBox.Margin = new System.Windows.Forms.Padding(4); this.TUNTAPDNSTextBox.Name = "TUNTAPDNSTextBox"; - this.TUNTAPDNSTextBox.Size = new System.Drawing.Size(294, 23); + this.TUNTAPDNSTextBox.Size = new System.Drawing.Size(439, 31); this.TUNTAPDNSTextBox.TabIndex = 8; this.TUNTAPDNSTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // TUNTAPGatewayLabel // this.TUNTAPGatewayLabel.AutoSize = true; - this.TUNTAPGatewayLabel.Location = new System.Drawing.Point(9, 83); + this.TUNTAPGatewayLabel.Location = new System.Drawing.Point(14, 124); + this.TUNTAPGatewayLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.TUNTAPGatewayLabel.Name = "TUNTAPGatewayLabel"; - this.TUNTAPGatewayLabel.Size = new System.Drawing.Size(57, 17); + this.TUNTAPGatewayLabel.Size = new System.Drawing.Size(84, 24); this.TUNTAPGatewayLabel.TabIndex = 5; this.TUNTAPGatewayLabel.Text = "Gateway"; // // TUNTAPGatewayTextBox // - this.TUNTAPGatewayTextBox.Location = new System.Drawing.Point(120, 80); + this.TUNTAPGatewayTextBox.Location = new System.Drawing.Point(180, 120); + this.TUNTAPGatewayTextBox.Margin = new System.Windows.Forms.Padding(4); this.TUNTAPGatewayTextBox.Name = "TUNTAPGatewayTextBox"; - this.TUNTAPGatewayTextBox.Size = new System.Drawing.Size(294, 23); + this.TUNTAPGatewayTextBox.Size = new System.Drawing.Size(439, 31); this.TUNTAPGatewayTextBox.TabIndex = 6; this.TUNTAPGatewayTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // TUNTAPNetmaskLabel // this.TUNTAPNetmaskLabel.AutoSize = true; - this.TUNTAPNetmaskLabel.Location = new System.Drawing.Point(9, 54); + this.TUNTAPNetmaskLabel.Location = new System.Drawing.Point(14, 81); + this.TUNTAPNetmaskLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.TUNTAPNetmaskLabel.Name = "TUNTAPNetmaskLabel"; - this.TUNTAPNetmaskLabel.Size = new System.Drawing.Size(60, 17); + this.TUNTAPNetmaskLabel.Size = new System.Drawing.Size(87, 24); this.TUNTAPNetmaskLabel.TabIndex = 3; this.TUNTAPNetmaskLabel.Text = "Netmask"; // // TUNTAPNetmaskTextBox // - this.TUNTAPNetmaskTextBox.Location = new System.Drawing.Point(120, 51); + this.TUNTAPNetmaskTextBox.Location = new System.Drawing.Point(180, 76); + this.TUNTAPNetmaskTextBox.Margin = new System.Windows.Forms.Padding(4); this.TUNTAPNetmaskTextBox.Name = "TUNTAPNetmaskTextBox"; - this.TUNTAPNetmaskTextBox.Size = new System.Drawing.Size(294, 23); + this.TUNTAPNetmaskTextBox.Size = new System.Drawing.Size(439, 31); this.TUNTAPNetmaskTextBox.TabIndex = 4; this.TUNTAPNetmaskTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // TUNTAPAddressLabel // this.TUNTAPAddressLabel.AutoSize = true; - this.TUNTAPAddressLabel.Location = new System.Drawing.Point(9, 25); + this.TUNTAPAddressLabel.Location = new System.Drawing.Point(14, 38); + this.TUNTAPAddressLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.TUNTAPAddressLabel.Name = "TUNTAPAddressLabel"; - this.TUNTAPAddressLabel.Size = new System.Drawing.Size(56, 17); + this.TUNTAPAddressLabel.Size = new System.Drawing.Size(80, 24); this.TUNTAPAddressLabel.TabIndex = 1; this.TUNTAPAddressLabel.Text = "Address"; // // TUNTAPAddressTextBox // - this.TUNTAPAddressTextBox.Location = new System.Drawing.Point(120, 22); + this.TUNTAPAddressTextBox.Location = new System.Drawing.Point(180, 33); + this.TUNTAPAddressTextBox.Margin = new System.Windows.Forms.Padding(4); this.TUNTAPAddressTextBox.Name = "TUNTAPAddressTextBox"; - this.TUNTAPAddressTextBox.Size = new System.Drawing.Size(294, 23); + this.TUNTAPAddressTextBox.Size = new System.Drawing.Size(439, 31); this.TUNTAPAddressTextBox.TabIndex = 2; this.TUNTAPAddressTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // ControlButton // this.ControlButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ControlButton.Location = new System.Drawing.Point(357, 648); + this.ControlButton.Location = new System.Drawing.Point(536, 1018); + this.ControlButton.Margin = new System.Windows.Forms.Padding(4); this.ControlButton.Name = "ControlButton"; - this.ControlButton.Size = new System.Drawing.Size(75, 23); + this.ControlButton.Size = new System.Drawing.Size(112, 34); this.ControlButton.TabIndex = 11; this.ControlButton.Text = "Save"; this.ControlButton.UseVisualStyleBackColor = true; @@ -235,9 +266,10 @@ // GlobalBypassIPsButton // this.GlobalBypassIPsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.GlobalBypassIPsButton.Location = new System.Drawing.Point(12, 648); + this.GlobalBypassIPsButton.Location = new System.Drawing.Point(18, 1018); + this.GlobalBypassIPsButton.Margin = new System.Windows.Forms.Padding(4); this.GlobalBypassIPsButton.Name = "GlobalBypassIPsButton"; - this.GlobalBypassIPsButton.Size = new System.Drawing.Size(128, 23); + this.GlobalBypassIPsButton.Size = new System.Drawing.Size(192, 34); this.GlobalBypassIPsButton.TabIndex = 10; this.GlobalBypassIPsButton.Text = "Global Bypass IPs"; this.GlobalBypassIPsButton.UseVisualStyleBackColor = true; @@ -257,63 +289,71 @@ this.BehaviorGroupBox.Controls.Add(this.StartWhenOpenedCheckBox); this.BehaviorGroupBox.Controls.Add(this.StopWhenExitedCheckBox); this.BehaviorGroupBox.Controls.Add(this.ExitWhenClosedCheckBox); - this.BehaviorGroupBox.Location = new System.Drawing.Point(12, 330); + this.BehaviorGroupBox.Location = new System.Drawing.Point(18, 526); + this.BehaviorGroupBox.Margin = new System.Windows.Forms.Padding(4); this.BehaviorGroupBox.Name = "BehaviorGroupBox"; - this.BehaviorGroupBox.Size = new System.Drawing.Size(420, 312); + this.BehaviorGroupBox.Padding = new System.Windows.Forms.Padding(4); + this.BehaviorGroupBox.Size = new System.Drawing.Size(630, 468); this.BehaviorGroupBox.TabIndex = 8; this.BehaviorGroupBox.TabStop = false; this.BehaviorGroupBox.Text = "Behavior"; // // STUN_ServerPortTextBox // - this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(120, 237); + this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(180, 356); + this.STUN_ServerPortTextBox.Margin = new System.Windows.Forms.Padding(4); this.STUN_ServerPortTextBox.Name = "STUN_ServerPortTextBox"; - this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(294, 23); + this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(439, 31); this.STUN_ServerPortTextBox.TabIndex = 8; this.STUN_ServerPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(9, 243); + this.label2.Location = new System.Drawing.Point(14, 364); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(110, 17); + this.label2.Size = new System.Drawing.Size(157, 24); this.label2.TabIndex = 12; this.label2.Text = "STUN Server Port"; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(9, 214); + this.label1.Location = new System.Drawing.Point(14, 321); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(82, 17); + this.label1.Size = new System.Drawing.Size(116, 24); this.label1.TabIndex = 10; this.label1.Text = "STUN Server"; // // RunAtStartup // this.RunAtStartup.AutoSize = true; - this.RunAtStartup.Location = new System.Drawing.Point(120, 130); + this.RunAtStartup.Location = new System.Drawing.Point(180, 195); + this.RunAtStartup.Margin = new System.Windows.Forms.Padding(4); this.RunAtStartup.Name = "RunAtStartup"; - this.RunAtStartup.Size = new System.Drawing.Size(109, 21); + this.RunAtStartup.Size = new System.Drawing.Size(159, 28); this.RunAtStartup.TabIndex = 11; this.RunAtStartup.Text = "Run at startup"; this.RunAtStartup.UseVisualStyleBackColor = true; // // STUN_ServerTextBox // - this.STUN_ServerTextBox.Location = new System.Drawing.Point(120, 211); + this.STUN_ServerTextBox.Location = new System.Drawing.Point(180, 316); + this.STUN_ServerTextBox.Margin = new System.Windows.Forms.Padding(4); this.STUN_ServerTextBox.Name = "STUN_ServerTextBox"; - this.STUN_ServerTextBox.Size = new System.Drawing.Size(294, 23); + this.STUN_ServerTextBox.Size = new System.Drawing.Size(439, 31); this.STUN_ServerTextBox.TabIndex = 11; this.STUN_ServerTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // MinimizeWhenStartedCheckBox // this.MinimizeWhenStartedCheckBox.AutoSize = true; - this.MinimizeWhenStartedCheckBox.Location = new System.Drawing.Point(120, 103); + this.MinimizeWhenStartedCheckBox.Location = new System.Drawing.Point(180, 154); + this.MinimizeWhenStartedCheckBox.Margin = new System.Windows.Forms.Padding(4); this.MinimizeWhenStartedCheckBox.Name = "MinimizeWhenStartedCheckBox"; - this.MinimizeWhenStartedCheckBox.Size = new System.Drawing.Size(158, 21); + this.MinimizeWhenStartedCheckBox.Size = new System.Drawing.Size(233, 28); this.MinimizeWhenStartedCheckBox.TabIndex = 10; this.MinimizeWhenStartedCheckBox.Text = "Minimize when started"; this.MinimizeWhenStartedCheckBox.UseVisualStyleBackColor = true; @@ -321,26 +361,29 @@ // ProfileCount_Label // this.ProfileCount_Label.AutoSize = true; - this.ProfileCount_Label.Location = new System.Drawing.Point(9, 185); + this.ProfileCount_Label.Location = new System.Drawing.Point(14, 278); + this.ProfileCount_Label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.ProfileCount_Label.Name = "ProfileCount_Label"; - this.ProfileCount_Label.Size = new System.Drawing.Size(79, 17); + this.ProfileCount_Label.Size = new System.Drawing.Size(117, 24); this.ProfileCount_Label.TabIndex = 8; this.ProfileCount_Label.Text = "ProfileCount"; // // ProfileCount_TextBox // - this.ProfileCount_TextBox.Location = new System.Drawing.Point(222, 182); + this.ProfileCount_TextBox.Location = new System.Drawing.Point(333, 273); + this.ProfileCount_TextBox.Margin = new System.Windows.Forms.Padding(4); this.ProfileCount_TextBox.Name = "ProfileCount_TextBox"; - this.ProfileCount_TextBox.Size = new System.Drawing.Size(192, 23); + this.ProfileCount_TextBox.Size = new System.Drawing.Size(286, 31); this.ProfileCount_TextBox.TabIndex = 9; this.ProfileCount_TextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // CheckUpdateWhenOpenedCheckBox // this.CheckUpdateWhenOpenedCheckBox.AutoSize = true; - this.CheckUpdateWhenOpenedCheckBox.Location = new System.Drawing.Point(120, 157); + this.CheckUpdateWhenOpenedCheckBox.Location = new System.Drawing.Point(180, 236); + this.CheckUpdateWhenOpenedCheckBox.Margin = new System.Windows.Forms.Padding(4); this.CheckUpdateWhenOpenedCheckBox.Name = "CheckUpdateWhenOpenedCheckBox"; - this.CheckUpdateWhenOpenedCheckBox.Size = new System.Drawing.Size(190, 21); + this.CheckUpdateWhenOpenedCheckBox.Size = new System.Drawing.Size(277, 28); this.CheckUpdateWhenOpenedCheckBox.TabIndex = 8; this.CheckUpdateWhenOpenedCheckBox.Text = "Check update when opened"; this.CheckUpdateWhenOpenedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -349,9 +392,10 @@ // StartWhenOpenedCheckBox // this.StartWhenOpenedCheckBox.AutoSize = true; - this.StartWhenOpenedCheckBox.Location = new System.Drawing.Point(120, 76); + this.StartWhenOpenedCheckBox.Location = new System.Drawing.Point(180, 114); + this.StartWhenOpenedCheckBox.Margin = new System.Windows.Forms.Padding(4); this.StartWhenOpenedCheckBox.Name = "StartWhenOpenedCheckBox"; - this.StartWhenOpenedCheckBox.Size = new System.Drawing.Size(137, 21); + this.StartWhenOpenedCheckBox.Size = new System.Drawing.Size(199, 28); this.StartWhenOpenedCheckBox.TabIndex = 7; this.StartWhenOpenedCheckBox.Text = "Start when opened"; this.StartWhenOpenedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -360,9 +404,10 @@ // StopWhenExitedCheckBox // this.StopWhenExitedCheckBox.AutoSize = true; - this.StopWhenExitedCheckBox.Location = new System.Drawing.Point(120, 49); + this.StopWhenExitedCheckBox.Location = new System.Drawing.Point(180, 74); + this.StopWhenExitedCheckBox.Margin = new System.Windows.Forms.Padding(4); this.StopWhenExitedCheckBox.Name = "StopWhenExitedCheckBox"; - this.StopWhenExitedCheckBox.Size = new System.Drawing.Size(127, 21); + this.StopWhenExitedCheckBox.Size = new System.Drawing.Size(185, 28); this.StopWhenExitedCheckBox.TabIndex = 6; this.StopWhenExitedCheckBox.Text = "Stop when exited"; this.StopWhenExitedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -371,9 +416,10 @@ // ExitWhenClosedCheckBox // this.ExitWhenClosedCheckBox.AutoSize = true; - this.ExitWhenClosedCheckBox.Location = new System.Drawing.Point(120, 22); + this.ExitWhenClosedCheckBox.Location = new System.Drawing.Point(180, 33); + this.ExitWhenClosedCheckBox.Margin = new System.Windows.Forms.Padding(4); this.ExitWhenClosedCheckBox.Name = "ExitWhenClosedCheckBox"; - this.ExitWhenClosedCheckBox.Size = new System.Drawing.Size(123, 21); + this.ExitWhenClosedCheckBox.Size = new System.Drawing.Size(178, 28); this.ExitWhenClosedCheckBox.TabIndex = 5; this.ExitWhenClosedCheckBox.Text = "Exit when closed"; this.ExitWhenClosedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -381,9 +427,9 @@ // // SettingForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.ClientSize = new System.Drawing.Size(444, 682); + this.ClientSize = new System.Drawing.Size(666, 1069); this.Controls.Add(this.BehaviorGroupBox); this.Controls.Add(this.PortGroupBox); this.Controls.Add(this.GlobalBypassIPsButton); @@ -392,7 +438,7 @@ this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6); this.MaximizeBox = false; this.Name = "SettingForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; @@ -442,5 +488,6 @@ private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox STUN_ServerTextBox; private System.Windows.Forms.TextBox STUN_ServerPortTextBox; + private System.Windows.Forms.CheckBox TUNTAPProxyDNSCheckBox; } } \ No newline at end of file diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index f2d72897..bb643378 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -52,6 +52,7 @@ namespace Netch.Forms TUNTAPNetmaskLabel.Text = Utils.i18N.Translate(TUNTAPNetmaskLabel.Text); TUNTAPGatewayLabel.Text = Utils.i18N.Translate(TUNTAPGatewayLabel.Text); TUNTAPUseCustomDNSCheckBox.Text = Utils.i18N.Translate(TUNTAPUseCustomDNSCheckBox.Text); + TUNTAPProxyDNSCheckBox.Text = Utils.i18N.Translate(TUNTAPProxyDNSCheckBox.Text); GlobalBypassIPsButton.Text = Utils.i18N.Translate(GlobalBypassIPsButton.Text); ControlButton.Text = Utils.i18N.Translate(ControlButton.Text); @@ -70,6 +71,7 @@ namespace Netch.Forms TUNTAPGatewayTextBox.Text = Global.Settings.TUNTAP.Gateway; TUNTAPUseCustomDNSCheckBox.Checked = Global.Settings.TUNTAP.UseCustomDNS; + TUNTAPProxyDNSCheckBox.Checked = Global.Settings.TUNTAP.ProxyDNS; BehaviorGroupBox.Text = Utils.i18N.Translate(BehaviorGroupBox.Text); ExitWhenClosedCheckBox.Text = Utils.i18N.Translate(ExitWhenClosedCheckBox.Text); @@ -320,10 +322,12 @@ namespace Netch.Forms } Global.Settings.TUNTAP.UseCustomDNS = TUNTAPUseCustomDNSCheckBox.Checked; + Global.Settings.TUNTAP.ProxyDNS = TUNTAPProxyDNSCheckBox.Checked; Utils.Configuration.Save(); MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } + } } diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index f2bd913f..979001c6 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -31,6 +31,11 @@ namespace Netch.Models /// 使用自定义 DNS 设置 /// public bool UseCustomDNS = false; + + /// + /// 模式2下是否代理DNS + /// + public bool ProxyDNS = false; } /// diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 1c8e6b63..5d5a581f 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -136,6 +136,7 @@ "Netmask": "子网掩码", "Gateway": "网关", "Use Custom DNS": "使用自定义 DNS", + "Proxy DNS in Mode 2": "在模式2下代理DNS", "Behavior": "行为", "Exit when closed": "关闭时退出", "Stop when exited": "退出时停止",