From b52b8b999e5844a62a5fe128818326de509791b2 Mon Sep 17 00:00:00 2001 From: M Sasan MH Date: Tue, 30 May 2023 19:54:13 +0430 Subject: [PATCH] v2.1.3 --- SecureDNSClient/Forms/FormMain.Designer.cs | 506 +++++++++++++----- SecureDNSClient/Forms/FormMain.cs | 185 +++++-- .../MsmhTools/HTTPProxyServer/DPIBypass.cs | 150 ++++-- .../HTTPProxyServer/HTTPProxyServer.cs | 131 +++-- .../MsmhTools/HTTPProxyServer/Request.cs | 12 +- .../MsmhTools/HTTPProxyServer/Tunnel.cs | 108 ++-- SecureDNSClient/MsmhTools/Network.cs | 84 ++- .../PublishProfiles/FolderProfile.pubxml.user | 2 +- SecureDNSClient/SecureDNS/SecureDNS.cs | 64 +-- SecureDNSClient/SecureDNSClient.csproj | 2 +- .../PublishProfiles/FolderProfile.pubxml.user | 2 +- .../SecureDNSClientPortable.csproj | 2 +- 12 files changed, 877 insertions(+), 371 deletions(-) diff --git a/SecureDNSClient/Forms/FormMain.Designer.cs b/SecureDNSClient/Forms/FormMain.Designer.cs index 58297c4..aaba5f7 100644 --- a/SecureDNSClient/Forms/FormMain.Designer.cs +++ b/SecureDNSClient/Forms/FormMain.Designer.cs @@ -64,16 +64,22 @@ private void InitializeComponent() this.CustomLabelSetDNSInfo = new CustomControls.CustomLabel(); this.CustomComboBoxNICs = new CustomControls.CustomComboBox(); this.TabPageShare = new System.Windows.Forms.TabPage(); + this.CustomCheckBoxHTTPProxyEventShowChunkDetails = new CustomControls.CustomCheckBox(); + this.CustomButtonPDpiApplyChanges = new CustomControls.CustomButton(); + this.CustomNumericUpDownPDpiFragDelay = new CustomControls.CustomNumericUpDown(); + this.CustomLabelPDpiFragDelay = new CustomControls.CustomLabel(); + this.CustomCheckBoxPDpiDontChunkBigData = new CustomControls.CustomCheckBox(); + this.CustomCheckBoxPDpiFragModeRandom = new CustomControls.CustomCheckBox(); this.CustomButtonSetProxy = new CustomControls.CustomButton(); - this.CustomNumericUpDownHTTPProxyDataLength = new CustomControls.CustomNumericUpDown(); - this.CustomLabelHTTPProxyDpiInfo1 = new CustomControls.CustomLabel(); - this.CustomNumericUpDownHTTPProxyFragmentSize = new CustomControls.CustomNumericUpDown(); - this.CustomLabelHTTPProxyDpiInfo2 = new CustomControls.CustomLabel(); + this.CustomNumericUpDownPDpiDataLength = new CustomControls.CustomNumericUpDown(); + this.CustomLabelPDpiDpiInfo1 = new CustomControls.CustomLabel(); + this.CustomNumericUpDownPDpiFragmentSize = new CustomControls.CustomNumericUpDown(); + this.CustomLabelPDpiDpiInfo2 = new CustomControls.CustomLabel(); this.CustomLabelShareSeparator1 = new CustomControls.CustomLabel(); this.CustomCheckBoxHTTPProxyEventShowRequest = new CustomControls.CustomCheckBox(); - this.CustomNumericUpDownHTTPProxyDivideBy = new CustomControls.CustomNumericUpDown(); - this.CustomLabelHTTPProxyDpiInfo3 = new CustomControls.CustomLabel(); - this.CustomCheckBoxHTTPProxyEnableDpiBypass = new CustomControls.CustomCheckBox(); + this.CustomNumericUpDownPDpiFragmentChunks = new CustomControls.CustomNumericUpDown(); + this.CustomLabelPDpiDpiInfo3 = new CustomControls.CustomLabel(); + this.CustomCheckBoxPDpiEnableDpiBypass = new CustomControls.CustomCheckBox(); this.CustomButtonShare = new CustomControls.CustomButton(); this.CustomLabelHTTPProxyPort = new CustomControls.CustomLabel(); this.CustomLabelShareInfo = new CustomControls.CustomLabel(); @@ -148,6 +154,13 @@ private void InitializeComponent() this.CustomLabelCheckSettingCamouflagePort = new CustomControls.CustomLabel(); this.CustomNumericUpDownSettingMaxServers = new CustomControls.CustomNumericUpDown(); this.CustomLabelSettingMaxServers = new CustomControls.CustomLabel(); + this.TabPageSettingsSetUnsetDNS = new System.Windows.Forms.TabPage(); + this.CustomTextBoxSettingUnsetDns2 = new CustomControls.CustomTextBox(); + this.CustomTextBoxSettingUnsetDns1 = new CustomControls.CustomTextBox(); + this.CustomLabelSettingUnsetDns2 = new CustomControls.CustomLabel(); + this.CustomLabelSettingUnsetDns1 = new CustomControls.CustomLabel(); + this.CustomRadioButtonSettingUnsetDnsToStatic = new CustomControls.CustomRadioButton(); + this.CustomRadioButtonSettingUnsetDnsToDhcp = new CustomControls.CustomRadioButton(); this.TabPageSettingsCPU = new System.Windows.Forms.TabPage(); this.CustomRadioButtonSettingCPULow = new CustomControls.CustomRadioButton(); this.CustomRadioButtonSettingCPUBelowNormal = new CustomControls.CustomRadioButton(); @@ -204,9 +217,10 @@ private void InitializeComponent() this.TabPageConnect.SuspendLayout(); this.TabPageSetDNS.SuspendLayout(); this.TabPageShare.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownHTTPProxyDataLength)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownHTTPProxyFragmentSize)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownHTTPProxyDivideBy)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownPDpiFragDelay)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownPDpiDataLength)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownPDpiFragmentSize)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownPDpiFragmentChunks)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownHTTPProxyPort)).BeginInit(); this.TabPageDPI.SuspendLayout(); this.CustomTabControlDPIBasicAdvanced.SuspendLayout(); @@ -228,6 +242,7 @@ private void InitializeComponent() this.TabPageSettingsConnect.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownSettingCamouflagePort)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownSettingMaxServers)).BeginInit(); + this.TabPageSettingsSetUnsetDNS.SuspendLayout(); this.TabPageSettingsCPU.SuspendLayout(); this.TabPageSettingsOthers.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownSettingFallbackDnsPort)).BeginInit(); @@ -590,7 +605,7 @@ private void InitializeComponent() this.CustomTabControlSecureDNS.SelectedIndex = 0; this.CustomTabControlSecureDNS.Size = new System.Drawing.Size(686, 278); this.CustomTabControlSecureDNS.TabIndex = 0; - this.CustomTabControlSecureDNS.Tag = 0; + this.CustomTabControlSecureDNS.Tag = 3; // // TabPageCheck // @@ -793,16 +808,22 @@ private void InitializeComponent() // TabPageShare // this.TabPageShare.BackColor = System.Drawing.Color.Transparent; + this.TabPageShare.Controls.Add(this.CustomCheckBoxHTTPProxyEventShowChunkDetails); + this.TabPageShare.Controls.Add(this.CustomButtonPDpiApplyChanges); + this.TabPageShare.Controls.Add(this.CustomNumericUpDownPDpiFragDelay); + this.TabPageShare.Controls.Add(this.CustomLabelPDpiFragDelay); + this.TabPageShare.Controls.Add(this.CustomCheckBoxPDpiDontChunkBigData); + this.TabPageShare.Controls.Add(this.CustomCheckBoxPDpiFragModeRandom); this.TabPageShare.Controls.Add(this.CustomButtonSetProxy); - this.TabPageShare.Controls.Add(this.CustomNumericUpDownHTTPProxyDataLength); - this.TabPageShare.Controls.Add(this.CustomLabelHTTPProxyDpiInfo1); - this.TabPageShare.Controls.Add(this.CustomNumericUpDownHTTPProxyFragmentSize); - this.TabPageShare.Controls.Add(this.CustomLabelHTTPProxyDpiInfo2); + this.TabPageShare.Controls.Add(this.CustomNumericUpDownPDpiDataLength); + this.TabPageShare.Controls.Add(this.CustomLabelPDpiDpiInfo1); + this.TabPageShare.Controls.Add(this.CustomNumericUpDownPDpiFragmentSize); + this.TabPageShare.Controls.Add(this.CustomLabelPDpiDpiInfo2); this.TabPageShare.Controls.Add(this.CustomLabelShareSeparator1); this.TabPageShare.Controls.Add(this.CustomCheckBoxHTTPProxyEventShowRequest); - this.TabPageShare.Controls.Add(this.CustomNumericUpDownHTTPProxyDivideBy); - this.TabPageShare.Controls.Add(this.CustomLabelHTTPProxyDpiInfo3); - this.TabPageShare.Controls.Add(this.CustomCheckBoxHTTPProxyEnableDpiBypass); + this.TabPageShare.Controls.Add(this.CustomNumericUpDownPDpiFragmentChunks); + this.TabPageShare.Controls.Add(this.CustomLabelPDpiDpiInfo3); + this.TabPageShare.Controls.Add(this.CustomCheckBoxPDpiEnableDpiBypass); this.TabPageShare.Controls.Add(this.CustomButtonShare); this.TabPageShare.Controls.Add(this.CustomLabelHTTPProxyPort); this.TabPageShare.Controls.Add(this.CustomLabelShareInfo); @@ -815,6 +836,87 @@ private void InitializeComponent() this.TabPageShare.Tag = 3; this.TabPageShare.Text = "4. Share + Bypass DPI"; // + // CustomCheckBoxHTTPProxyEventShowChunkDetails + // + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.BackColor = System.Drawing.Color.DimGray; + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.BorderColor = System.Drawing.Color.Blue; + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.CheckColor = System.Drawing.Color.Blue; + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.ForeColor = System.Drawing.Color.White; + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.Location = new System.Drawing.Point(480, 50); + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.Name = "CustomCheckBoxHTTPProxyEventShowChunkDetails"; + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.SelectionColor = System.Drawing.Color.LightBlue; + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.Size = new System.Drawing.Size(161, 17); + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.TabIndex = 38; + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.Text = "Write chunk details to log"; + this.CustomCheckBoxHTTPProxyEventShowChunkDetails.UseVisualStyleBackColor = false; + // + // CustomButtonPDpiApplyChanges + // + this.CustomButtonPDpiApplyChanges.BorderColor = System.Drawing.Color.Blue; + this.CustomButtonPDpiApplyChanges.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.CustomButtonPDpiApplyChanges.Location = new System.Drawing.Point(272, 220); + this.CustomButtonPDpiApplyChanges.Name = "CustomButtonPDpiApplyChanges"; + this.CustomButtonPDpiApplyChanges.RoundedCorners = 0; + this.CustomButtonPDpiApplyChanges.SelectionColor = System.Drawing.Color.LightBlue; + this.CustomButtonPDpiApplyChanges.Size = new System.Drawing.Size(150, 23); + this.CustomButtonPDpiApplyChanges.TabIndex = 37; + this.CustomButtonPDpiApplyChanges.Text = "Apply DPI bypass changes"; + this.CustomButtonPDpiApplyChanges.UseVisualStyleBackColor = true; + this.CustomButtonPDpiApplyChanges.Click += new System.EventHandler(this.CustomButtonPDpiApplyChanges_Click); + // + // CustomNumericUpDownPDpiFragDelay + // + this.CustomNumericUpDownPDpiFragDelay.BackColor = System.Drawing.Color.DimGray; + this.CustomNumericUpDownPDpiFragDelay.BorderColor = System.Drawing.Color.Blue; + this.CustomNumericUpDownPDpiFragDelay.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.CustomNumericUpDownPDpiFragDelay.Location = new System.Drawing.Point(377, 183); + this.CustomNumericUpDownPDpiFragDelay.Name = "CustomNumericUpDownPDpiFragDelay"; + this.CustomNumericUpDownPDpiFragDelay.Size = new System.Drawing.Size(45, 23); + this.CustomNumericUpDownPDpiFragDelay.TabIndex = 36; + // + // CustomLabelPDpiFragDelay + // + this.CustomLabelPDpiFragDelay.AutoSize = true; + this.CustomLabelPDpiFragDelay.BackColor = System.Drawing.Color.DimGray; + this.CustomLabelPDpiFragDelay.Border = false; + this.CustomLabelPDpiFragDelay.BorderColor = System.Drawing.Color.Blue; + this.CustomLabelPDpiFragDelay.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.CustomLabelPDpiFragDelay.ForeColor = System.Drawing.Color.White; + this.CustomLabelPDpiFragDelay.Location = new System.Drawing.Point(250, 185); + this.CustomLabelPDpiFragDelay.Name = "CustomLabelPDpiFragDelay"; + this.CustomLabelPDpiFragDelay.RoundedCorners = 0; + this.CustomLabelPDpiFragDelay.Size = new System.Drawing.Size(121, 17); + this.CustomLabelPDpiFragDelay.TabIndex = 35; + this.CustomLabelPDpiFragDelay.Text = "Fragment delay (ms):"; + // + // CustomCheckBoxPDpiDontChunkBigData + // + this.CustomCheckBoxPDpiDontChunkBigData.BackColor = System.Drawing.Color.DimGray; + this.CustomCheckBoxPDpiDontChunkBigData.BorderColor = System.Drawing.Color.Blue; + this.CustomCheckBoxPDpiDontChunkBigData.CheckColor = System.Drawing.Color.Blue; + this.CustomCheckBoxPDpiDontChunkBigData.ForeColor = System.Drawing.Color.White; + this.CustomCheckBoxPDpiDontChunkBigData.Location = new System.Drawing.Point(54, 185); + this.CustomCheckBoxPDpiDontChunkBigData.Name = "CustomCheckBoxPDpiDontChunkBigData"; + this.CustomCheckBoxPDpiDontChunkBigData.SelectionColor = System.Drawing.Color.LightBlue; + this.CustomCheckBoxPDpiDontChunkBigData.Size = new System.Drawing.Size(182, 17); + this.CustomCheckBoxPDpiDontChunkBigData.TabIndex = 34; + this.CustomCheckBoxPDpiDontChunkBigData.Text = "Don\'t chunk the biggest data."; + this.CustomCheckBoxPDpiDontChunkBigData.UseVisualStyleBackColor = false; + // + // CustomCheckBoxPDpiFragModeRandom + // + this.CustomCheckBoxPDpiFragModeRandom.BackColor = System.Drawing.Color.DimGray; + this.CustomCheckBoxPDpiFragModeRandom.BorderColor = System.Drawing.Color.Blue; + this.CustomCheckBoxPDpiFragModeRandom.CheckColor = System.Drawing.Color.Blue; + this.CustomCheckBoxPDpiFragModeRandom.ForeColor = System.Drawing.Color.White; + this.CustomCheckBoxPDpiFragModeRandom.Location = new System.Drawing.Point(298, 150); + this.CustomCheckBoxPDpiFragModeRandom.Name = "CustomCheckBoxPDpiFragModeRandom"; + this.CustomCheckBoxPDpiFragModeRandom.SelectionColor = System.Drawing.Color.LightBlue; + this.CustomCheckBoxPDpiFragModeRandom.Size = new System.Drawing.Size(101, 17); + this.CustomCheckBoxPDpiFragModeRandom.TabIndex = 33; + this.CustomCheckBoxPDpiFragModeRandom.Text = "Random mode"; + this.CustomCheckBoxPDpiFragModeRandom.UseVisualStyleBackColor = false; + // // CustomButtonSetProxy // this.CustomButtonSetProxy.BorderColor = System.Drawing.Color.Blue; @@ -829,85 +931,85 @@ private void InitializeComponent() this.CustomButtonSetProxy.UseVisualStyleBackColor = true; this.CustomButtonSetProxy.Click += new System.EventHandler(this.CustomButtonSetProxy_Click); // - // CustomNumericUpDownHTTPProxyDataLength + // CustomNumericUpDownPDpiDataLength // - this.CustomNumericUpDownHTTPProxyDataLength.BackColor = System.Drawing.Color.DimGray; - this.CustomNumericUpDownHTTPProxyDataLength.BorderColor = System.Drawing.Color.Blue; - this.CustomNumericUpDownHTTPProxyDataLength.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.CustomNumericUpDownHTTPProxyDataLength.Location = new System.Drawing.Point(195, 133); - this.CustomNumericUpDownHTTPProxyDataLength.Maximum = new decimal(new int[] { + this.CustomNumericUpDownPDpiDataLength.BackColor = System.Drawing.Color.DimGray; + this.CustomNumericUpDownPDpiDataLength.BorderColor = System.Drawing.Color.Blue; + this.CustomNumericUpDownPDpiDataLength.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.CustomNumericUpDownPDpiDataLength.Location = new System.Drawing.Point(165, 113); + this.CustomNumericUpDownPDpiDataLength.Maximum = new decimal(new int[] { 65536, 0, 0, 0}); - this.CustomNumericUpDownHTTPProxyDataLength.Minimum = new decimal(new int[] { + this.CustomNumericUpDownPDpiDataLength.Minimum = new decimal(new int[] { 1, 0, 0, 0}); - this.CustomNumericUpDownHTTPProxyDataLength.Name = "CustomNumericUpDownHTTPProxyDataLength"; - this.CustomNumericUpDownHTTPProxyDataLength.Size = new System.Drawing.Size(55, 23); - this.CustomNumericUpDownHTTPProxyDataLength.TabIndex = 31; - this.CustomNumericUpDownHTTPProxyDataLength.Value = new decimal(new int[] { + this.CustomNumericUpDownPDpiDataLength.Name = "CustomNumericUpDownPDpiDataLength"; + this.CustomNumericUpDownPDpiDataLength.Size = new System.Drawing.Size(55, 23); + this.CustomNumericUpDownPDpiDataLength.TabIndex = 31; + this.CustomNumericUpDownPDpiDataLength.Value = new decimal(new int[] { 60, 0, 0, 0}); // - // CustomLabelHTTPProxyDpiInfo1 - // - this.CustomLabelHTTPProxyDpiInfo1.AutoSize = true; - this.CustomLabelHTTPProxyDpiInfo1.BackColor = System.Drawing.Color.DimGray; - this.CustomLabelHTTPProxyDpiInfo1.Border = false; - this.CustomLabelHTTPProxyDpiInfo1.BorderColor = System.Drawing.Color.Blue; - this.CustomLabelHTTPProxyDpiInfo1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.CustomLabelHTTPProxyDpiInfo1.ForeColor = System.Drawing.Color.White; - this.CustomLabelHTTPProxyDpiInfo1.Location = new System.Drawing.Point(50, 135); - this.CustomLabelHTTPProxyDpiInfo1.Name = "CustomLabelHTTPProxyDpiInfo1"; - this.CustomLabelHTTPProxyDpiInfo1.RoundedCorners = 0; - this.CustomLabelHTTPProxyDpiInfo1.Size = new System.Drawing.Size(137, 15); - this.CustomLabelHTTPProxyDpiInfo1.TabIndex = 30; - this.CustomLabelHTTPProxyDpiInfo1.Text = "If data length is less than"; - // - // CustomNumericUpDownHTTPProxyFragmentSize - // - this.CustomNumericUpDownHTTPProxyFragmentSize.BackColor = System.Drawing.Color.DimGray; - this.CustomNumericUpDownHTTPProxyFragmentSize.BorderColor = System.Drawing.Color.Blue; - this.CustomNumericUpDownHTTPProxyFragmentSize.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.CustomNumericUpDownHTTPProxyFragmentSize.Location = new System.Drawing.Point(374, 133); - this.CustomNumericUpDownHTTPProxyFragmentSize.Maximum = new decimal(new int[] { + // CustomLabelPDpiDpiInfo1 + // + this.CustomLabelPDpiDpiInfo1.AutoSize = true; + this.CustomLabelPDpiDpiInfo1.BackColor = System.Drawing.Color.DimGray; + this.CustomLabelPDpiDpiInfo1.Border = false; + this.CustomLabelPDpiDpiInfo1.BorderColor = System.Drawing.Color.Blue; + this.CustomLabelPDpiDpiInfo1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.CustomLabelPDpiDpiInfo1.ForeColor = System.Drawing.Color.White; + this.CustomLabelPDpiDpiInfo1.Location = new System.Drawing.Point(50, 115); + this.CustomLabelPDpiDpiInfo1.Name = "CustomLabelPDpiDpiInfo1"; + this.CustomLabelPDpiDpiInfo1.RoundedCorners = 0; + this.CustomLabelPDpiDpiInfo1.Size = new System.Drawing.Size(109, 17); + this.CustomLabelPDpiDpiInfo1.TabIndex = 30; + this.CustomLabelPDpiDpiInfo1.Text = "If data length is <="; + // + // CustomNumericUpDownPDpiFragmentSize + // + this.CustomNumericUpDownPDpiFragmentSize.BackColor = System.Drawing.Color.DimGray; + this.CustomNumericUpDownPDpiFragmentSize.BorderColor = System.Drawing.Color.Blue; + this.CustomNumericUpDownPDpiFragmentSize.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.CustomNumericUpDownPDpiFragmentSize.Location = new System.Drawing.Point(344, 113); + this.CustomNumericUpDownPDpiFragmentSize.Maximum = new decimal(new int[] { 65536, 0, 0, 0}); - this.CustomNumericUpDownHTTPProxyFragmentSize.Minimum = new decimal(new int[] { + this.CustomNumericUpDownPDpiFragmentSize.Minimum = new decimal(new int[] { 1, 0, 0, 0}); - this.CustomNumericUpDownHTTPProxyFragmentSize.Name = "CustomNumericUpDownHTTPProxyFragmentSize"; - this.CustomNumericUpDownHTTPProxyFragmentSize.Size = new System.Drawing.Size(55, 23); - this.CustomNumericUpDownHTTPProxyFragmentSize.TabIndex = 28; - this.CustomNumericUpDownHTTPProxyFragmentSize.Value = new decimal(new int[] { + this.CustomNumericUpDownPDpiFragmentSize.Name = "CustomNumericUpDownPDpiFragmentSize"; + this.CustomNumericUpDownPDpiFragmentSize.Size = new System.Drawing.Size(55, 23); + this.CustomNumericUpDownPDpiFragmentSize.TabIndex = 28; + this.CustomNumericUpDownPDpiFragmentSize.Value = new decimal(new int[] { 2, 0, 0, 0}); // - // CustomLabelHTTPProxyDpiInfo2 - // - this.CustomLabelHTTPProxyDpiInfo2.AutoSize = true; - this.CustomLabelHTTPProxyDpiInfo2.BackColor = System.Drawing.Color.DimGray; - this.CustomLabelHTTPProxyDpiInfo2.Border = false; - this.CustomLabelHTTPProxyDpiInfo2.BorderColor = System.Drawing.Color.Blue; - this.CustomLabelHTTPProxyDpiInfo2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.CustomLabelHTTPProxyDpiInfo2.ForeColor = System.Drawing.Color.White; - this.CustomLabelHTTPProxyDpiInfo2.Location = new System.Drawing.Point(256, 135); - this.CustomLabelHTTPProxyDpiInfo2.Name = "CustomLabelHTTPProxyDpiInfo2"; - this.CustomLabelHTTPProxyDpiInfo2.RoundedCorners = 0; - this.CustomLabelHTTPProxyDpiInfo2.Size = new System.Drawing.Size(110, 15); - this.CustomLabelHTTPProxyDpiInfo2.TabIndex = 27; - this.CustomLabelHTTPProxyDpiInfo2.Text = "set fragment size to"; + // CustomLabelPDpiDpiInfo2 + // + this.CustomLabelPDpiDpiInfo2.AutoSize = true; + this.CustomLabelPDpiDpiInfo2.BackColor = System.Drawing.Color.DimGray; + this.CustomLabelPDpiDpiInfo2.Border = false; + this.CustomLabelPDpiDpiInfo2.BorderColor = System.Drawing.Color.Blue; + this.CustomLabelPDpiDpiInfo2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.CustomLabelPDpiDpiInfo2.ForeColor = System.Drawing.Color.White; + this.CustomLabelPDpiDpiInfo2.Location = new System.Drawing.Point(226, 115); + this.CustomLabelPDpiDpiInfo2.Name = "CustomLabelPDpiDpiInfo2"; + this.CustomLabelPDpiDpiInfo2.RoundedCorners = 0; + this.CustomLabelPDpiDpiInfo2.Size = new System.Drawing.Size(112, 17); + this.CustomLabelPDpiDpiInfo2.TabIndex = 27; + this.CustomLabelPDpiDpiInfo2.Text = "set fragment size to"; // // CustomLabelShareSeparator1 // @@ -916,7 +1018,7 @@ private void InitializeComponent() this.CustomLabelShareSeparator1.BorderColor = System.Drawing.Color.Blue; this.CustomLabelShareSeparator1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.CustomLabelShareSeparator1.ForeColor = System.Drawing.Color.White; - this.CustomLabelShareSeparator1.Location = new System.Drawing.Point(20, 85); + this.CustomLabelShareSeparator1.Location = new System.Drawing.Point(20, 80); this.CustomLabelShareSeparator1.Name = "CustomLabelShareSeparator1"; this.CustomLabelShareSeparator1.RoundedCorners = 0; this.CustomLabelShareSeparator1.Size = new System.Drawing.Size(640, 1); @@ -928,7 +1030,7 @@ private void InitializeComponent() this.CustomCheckBoxHTTPProxyEventShowRequest.BorderColor = System.Drawing.Color.Blue; this.CustomCheckBoxHTTPProxyEventShowRequest.CheckColor = System.Drawing.Color.Blue; this.CustomCheckBoxHTTPProxyEventShowRequest.ForeColor = System.Drawing.Color.White; - this.CustomCheckBoxHTTPProxyEventShowRequest.Location = new System.Drawing.Point(355, 50); + this.CustomCheckBoxHTTPProxyEventShowRequest.Location = new System.Drawing.Point(320, 50); this.CustomCheckBoxHTTPProxyEventShowRequest.Name = "CustomCheckBoxHTTPProxyEventShowRequest"; this.CustomCheckBoxHTTPProxyEventShowRequest.SelectionColor = System.Drawing.Color.LightBlue; this.CustomCheckBoxHTTPProxyEventShowRequest.Size = new System.Drawing.Size(135, 17); @@ -936,61 +1038,61 @@ private void InitializeComponent() this.CustomCheckBoxHTTPProxyEventShowRequest.Text = "Write requests to log"; this.CustomCheckBoxHTTPProxyEventShowRequest.UseVisualStyleBackColor = false; // - // CustomNumericUpDownHTTPProxyDivideBy + // CustomNumericUpDownPDpiFragmentChunks // - this.CustomNumericUpDownHTTPProxyDivideBy.BackColor = System.Drawing.Color.DimGray; - this.CustomNumericUpDownHTTPProxyDivideBy.BorderColor = System.Drawing.Color.Blue; - this.CustomNumericUpDownHTTPProxyDivideBy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.CustomNumericUpDownHTTPProxyDivideBy.Location = new System.Drawing.Point(318, 168); - this.CustomNumericUpDownHTTPProxyDivideBy.Maximum = new decimal(new int[] { + this.CustomNumericUpDownPDpiFragmentChunks.BackColor = System.Drawing.Color.DimGray; + this.CustomNumericUpDownPDpiFragmentChunks.BorderColor = System.Drawing.Color.Blue; + this.CustomNumericUpDownPDpiFragmentChunks.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.CustomNumericUpDownPDpiFragmentChunks.Location = new System.Drawing.Point(220, 148); + this.CustomNumericUpDownPDpiFragmentChunks.Maximum = new decimal(new int[] { 500, 0, 0, 0}); - this.CustomNumericUpDownHTTPProxyDivideBy.Minimum = new decimal(new int[] { + this.CustomNumericUpDownPDpiFragmentChunks.Minimum = new decimal(new int[] { 1, 0, 0, 0}); - this.CustomNumericUpDownHTTPProxyDivideBy.Name = "CustomNumericUpDownHTTPProxyDivideBy"; - this.CustomNumericUpDownHTTPProxyDivideBy.Size = new System.Drawing.Size(50, 23); - this.CustomNumericUpDownHTTPProxyDivideBy.TabIndex = 19; - this.CustomNumericUpDownHTTPProxyDivideBy.Value = new decimal(new int[] { + this.CustomNumericUpDownPDpiFragmentChunks.Name = "CustomNumericUpDownPDpiFragmentChunks"; + this.CustomNumericUpDownPDpiFragmentChunks.Size = new System.Drawing.Size(50, 23); + this.CustomNumericUpDownPDpiFragmentChunks.TabIndex = 19; + this.CustomNumericUpDownPDpiFragmentChunks.Value = new decimal(new int[] { 60, 0, 0, 0}); // - // CustomLabelHTTPProxyDpiInfo3 - // - this.CustomLabelHTTPProxyDpiInfo3.AutoSize = true; - this.CustomLabelHTTPProxyDpiInfo3.BackColor = System.Drawing.Color.DimGray; - this.CustomLabelHTTPProxyDpiInfo3.Border = false; - this.CustomLabelHTTPProxyDpiInfo3.BorderColor = System.Drawing.Color.Blue; - this.CustomLabelHTTPProxyDpiInfo3.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.CustomLabelHTTPProxyDpiInfo3.ForeColor = System.Drawing.Color.White; - this.CustomLabelHTTPProxyDpiInfo3.Location = new System.Drawing.Point(50, 170); - this.CustomLabelHTTPProxyDpiInfo3.Name = "CustomLabelHTTPProxyDpiInfo3"; - this.CustomLabelHTTPProxyDpiInfo3.RoundedCorners = 0; - this.CustomLabelHTTPProxyDpiInfo3.Size = new System.Drawing.Size(260, 15); - this.CustomLabelHTTPProxyDpiInfo3.TabIndex = 18; - this.CustomLabelHTTPProxyDpiInfo3.Text = "else set fragment size by dividing data length by"; - // - // CustomCheckBoxHTTPProxyEnableDpiBypass - // - this.CustomCheckBoxHTTPProxyEnableDpiBypass.BackColor = System.Drawing.Color.DimGray; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.BorderColor = System.Drawing.Color.Blue; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.CheckColor = System.Drawing.Color.Blue; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.Checked = true; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.CheckState = System.Windows.Forms.CheckState.Checked; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.ForeColor = System.Drawing.Color.White; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.Location = new System.Drawing.Point(25, 100); - this.CustomCheckBoxHTTPProxyEnableDpiBypass.Name = "CustomCheckBoxHTTPProxyEnableDpiBypass"; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.SelectionColor = System.Drawing.Color.LightBlue; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.Size = new System.Drawing.Size(120, 17); - this.CustomCheckBoxHTTPProxyEnableDpiBypass.TabIndex = 17; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.Text = "Enable DPI bypass"; - this.CustomCheckBoxHTTPProxyEnableDpiBypass.UseVisualStyleBackColor = false; + // CustomLabelPDpiDpiInfo3 + // + this.CustomLabelPDpiDpiInfo3.AutoSize = true; + this.CustomLabelPDpiDpiInfo3.BackColor = System.Drawing.Color.DimGray; + this.CustomLabelPDpiDpiInfo3.Border = false; + this.CustomLabelPDpiDpiInfo3.BorderColor = System.Drawing.Color.Blue; + this.CustomLabelPDpiDpiInfo3.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.CustomLabelPDpiDpiInfo3.ForeColor = System.Drawing.Color.White; + this.CustomLabelPDpiDpiInfo3.Location = new System.Drawing.Point(50, 150); + this.CustomLabelPDpiDpiInfo3.Name = "CustomLabelPDpiDpiInfo3"; + this.CustomLabelPDpiDpiInfo3.RoundedCorners = 0; + this.CustomLabelPDpiDpiInfo3.Size = new System.Drawing.Size(164, 17); + this.CustomLabelPDpiDpiInfo3.TabIndex = 18; + this.CustomLabelPDpiDpiInfo3.Text = "else chunk data into n pieces:"; + // + // CustomCheckBoxPDpiEnableDpiBypass + // + this.CustomCheckBoxPDpiEnableDpiBypass.BackColor = System.Drawing.Color.DimGray; + this.CustomCheckBoxPDpiEnableDpiBypass.BorderColor = System.Drawing.Color.Blue; + this.CustomCheckBoxPDpiEnableDpiBypass.CheckColor = System.Drawing.Color.Blue; + this.CustomCheckBoxPDpiEnableDpiBypass.Checked = true; + this.CustomCheckBoxPDpiEnableDpiBypass.CheckState = System.Windows.Forms.CheckState.Checked; + this.CustomCheckBoxPDpiEnableDpiBypass.ForeColor = System.Drawing.Color.White; + this.CustomCheckBoxPDpiEnableDpiBypass.Location = new System.Drawing.Point(25, 90); + this.CustomCheckBoxPDpiEnableDpiBypass.Name = "CustomCheckBoxPDpiEnableDpiBypass"; + this.CustomCheckBoxPDpiEnableDpiBypass.SelectionColor = System.Drawing.Color.LightBlue; + this.CustomCheckBoxPDpiEnableDpiBypass.Size = new System.Drawing.Size(120, 17); + this.CustomCheckBoxPDpiEnableDpiBypass.TabIndex = 17; + this.CustomCheckBoxPDpiEnableDpiBypass.Text = "Enable DPI bypass"; + this.CustomCheckBoxPDpiEnableDpiBypass.UseVisualStyleBackColor = false; // // CustomButtonShare // @@ -1017,7 +1119,7 @@ private void InitializeComponent() this.CustomLabelHTTPProxyPort.Location = new System.Drawing.Point(25, 50); this.CustomLabelHTTPProxyPort.Name = "CustomLabelHTTPProxyPort"; this.CustomLabelHTTPProxyPort.RoundedCorners = 0; - this.CustomLabelHTTPProxyPort.Size = new System.Drawing.Size(99, 15); + this.CustomLabelHTTPProxyPort.Size = new System.Drawing.Size(101, 17); this.CustomLabelHTTPProxyPort.TabIndex = 15; this.CustomLabelHTTPProxyPort.Text = "HTTP Proxy. Port:"; // @@ -1033,7 +1135,7 @@ private void InitializeComponent() this.CustomLabelShareInfo.Location = new System.Drawing.Point(25, 10); this.CustomLabelShareInfo.Name = "CustomLabelShareInfo"; this.CustomLabelShareInfo.RoundedCorners = 0; - this.CustomLabelShareInfo.Size = new System.Drawing.Size(421, 21); + this.CustomLabelShareInfo.Size = new System.Drawing.Size(423, 23); this.CustomLabelShareInfo.TabIndex = 14; this.CustomLabelShareInfo.Text = "Share to other devices on the same network. (Experimental)"; // @@ -1910,6 +2012,7 @@ private void InitializeComponent() this.CustomTabControlSettings.Controls.Add(this.TabPageSettingsWorkingMode); this.CustomTabControlSettings.Controls.Add(this.TabPageSettingsCheck); this.CustomTabControlSettings.Controls.Add(this.TabPageSettingsConnect); + this.CustomTabControlSettings.Controls.Add(this.TabPageSettingsSetUnsetDNS); this.CustomTabControlSettings.Controls.Add(this.TabPageSettingsCPU); this.CustomTabControlSettings.Controls.Add(this.TabPageSettingsOthers); this.CustomTabControlSettings.HideTabHeader = false; @@ -1923,7 +2026,7 @@ private void InitializeComponent() this.CustomTabControlSettings.Size = new System.Drawing.Size(688, 278); this.CustomTabControlSettings.SizeMode = System.Windows.Forms.TabSizeMode.Fixed; this.CustomTabControlSettings.TabIndex = 10; - this.CustomTabControlSettings.Tag = 4; + this.CustomTabControlSettings.Tag = 3; // // TabPageSettingsWorkingMode // @@ -2276,6 +2379,137 @@ private void InitializeComponent() this.CustomLabelSettingMaxServers.TabIndex = 6; this.CustomLabelSettingMaxServers.Text = "Maximum number of servers to connect:"; // + // TabPageSettingsSetUnsetDNS + // + this.TabPageSettingsSetUnsetDNS.BackColor = System.Drawing.Color.Transparent; + this.TabPageSettingsSetUnsetDNS.Controls.Add(this.CustomTextBoxSettingUnsetDns2); + this.TabPageSettingsSetUnsetDNS.Controls.Add(this.CustomTextBoxSettingUnsetDns1); + this.TabPageSettingsSetUnsetDNS.Controls.Add(this.CustomLabelSettingUnsetDns2); + this.TabPageSettingsSetUnsetDNS.Controls.Add(this.CustomLabelSettingUnsetDns1); + this.TabPageSettingsSetUnsetDNS.Controls.Add(this.CustomRadioButtonSettingUnsetDnsToStatic); + this.TabPageSettingsSetUnsetDNS.Controls.Add(this.CustomRadioButtonSettingUnsetDnsToDhcp); + this.TabPageSettingsSetUnsetDNS.Location = new System.Drawing.Point(94, 4); + this.TabPageSettingsSetUnsetDNS.Name = "TabPageSettingsSetUnsetDNS"; + this.TabPageSettingsSetUnsetDNS.Padding = new System.Windows.Forms.Padding(3); + this.TabPageSettingsSetUnsetDNS.Size = new System.Drawing.Size(590, 270); + this.TabPageSettingsSetUnsetDNS.TabIndex = 5; + this.TabPageSettingsSetUnsetDNS.Tag = 3; + this.TabPageSettingsSetUnsetDNS.Text = "Set/Unset DNS"; + // + // CustomTextBoxSettingUnsetDns2 + // + this.CustomTextBoxSettingUnsetDns2.AcceptsReturn = false; + this.CustomTextBoxSettingUnsetDns2.AcceptsTab = false; + this.CustomTextBoxSettingUnsetDns2.BackColor = System.Drawing.Color.DimGray; + this.CustomTextBoxSettingUnsetDns2.Border = true; + this.CustomTextBoxSettingUnsetDns2.BorderColor = System.Drawing.Color.Blue; + this.CustomTextBoxSettingUnsetDns2.BorderSize = 1; + this.CustomTextBoxSettingUnsetDns2.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal; + this.CustomTextBoxSettingUnsetDns2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.CustomTextBoxSettingUnsetDns2.ForeColor = System.Drawing.Color.White; + this.CustomTextBoxSettingUnsetDns2.HideSelection = true; + this.CustomTextBoxSettingUnsetDns2.Location = new System.Drawing.Point(183, 128); + this.CustomTextBoxSettingUnsetDns2.MaxLength = 32767; + this.CustomTextBoxSettingUnsetDns2.Multiline = false; + this.CustomTextBoxSettingUnsetDns2.Name = "CustomTextBoxSettingUnsetDns2"; + this.CustomTextBoxSettingUnsetDns2.ReadOnly = false; + this.CustomTextBoxSettingUnsetDns2.ScrollBars = System.Windows.Forms.ScrollBars.None; + this.CustomTextBoxSettingUnsetDns2.ShortcutsEnabled = true; + this.CustomTextBoxSettingUnsetDns2.Size = new System.Drawing.Size(100, 23); + this.CustomTextBoxSettingUnsetDns2.TabIndex = 0; + this.CustomTextBoxSettingUnsetDns2.TextAlign = System.Windows.Forms.HorizontalAlignment.Left; + this.CustomTextBoxSettingUnsetDns2.Texts = "8.8.4.4"; + this.CustomTextBoxSettingUnsetDns2.UnderlinedStyle = false; + this.CustomTextBoxSettingUnsetDns2.UsePasswordChar = false; + this.CustomTextBoxSettingUnsetDns2.WordWrap = true; + // + // CustomTextBoxSettingUnsetDns1 + // + this.CustomTextBoxSettingUnsetDns1.AcceptsReturn = false; + this.CustomTextBoxSettingUnsetDns1.AcceptsTab = false; + this.CustomTextBoxSettingUnsetDns1.BackColor = System.Drawing.Color.DimGray; + this.CustomTextBoxSettingUnsetDns1.Border = true; + this.CustomTextBoxSettingUnsetDns1.BorderColor = System.Drawing.Color.Blue; + this.CustomTextBoxSettingUnsetDns1.BorderSize = 1; + this.CustomTextBoxSettingUnsetDns1.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal; + this.CustomTextBoxSettingUnsetDns1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.CustomTextBoxSettingUnsetDns1.ForeColor = System.Drawing.Color.White; + this.CustomTextBoxSettingUnsetDns1.HideSelection = true; + this.CustomTextBoxSettingUnsetDns1.Location = new System.Drawing.Point(183, 93); + this.CustomTextBoxSettingUnsetDns1.MaxLength = 32767; + this.CustomTextBoxSettingUnsetDns1.Multiline = false; + this.CustomTextBoxSettingUnsetDns1.Name = "CustomTextBoxSettingUnsetDns1"; + this.CustomTextBoxSettingUnsetDns1.ReadOnly = false; + this.CustomTextBoxSettingUnsetDns1.ScrollBars = System.Windows.Forms.ScrollBars.None; + this.CustomTextBoxSettingUnsetDns1.ShortcutsEnabled = true; + this.CustomTextBoxSettingUnsetDns1.Size = new System.Drawing.Size(100, 23); + this.CustomTextBoxSettingUnsetDns1.TabIndex = 0; + this.CustomTextBoxSettingUnsetDns1.TextAlign = System.Windows.Forms.HorizontalAlignment.Left; + this.CustomTextBoxSettingUnsetDns1.Texts = "8.8.8.8"; + this.CustomTextBoxSettingUnsetDns1.UnderlinedStyle = false; + this.CustomTextBoxSettingUnsetDns1.UsePasswordChar = false; + this.CustomTextBoxSettingUnsetDns1.WordWrap = true; + // + // CustomLabelSettingUnsetDns2 + // + this.CustomLabelSettingUnsetDns2.AutoSize = true; + this.CustomLabelSettingUnsetDns2.BackColor = System.Drawing.Color.DimGray; + this.CustomLabelSettingUnsetDns2.Border = false; + this.CustomLabelSettingUnsetDns2.BorderColor = System.Drawing.Color.Blue; + this.CustomLabelSettingUnsetDns2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.CustomLabelSettingUnsetDns2.ForeColor = System.Drawing.Color.White; + this.CustomLabelSettingUnsetDns2.Location = new System.Drawing.Point(110, 130); + this.CustomLabelSettingUnsetDns2.Name = "CustomLabelSettingUnsetDns2"; + this.CustomLabelSettingUnsetDns2.RoundedCorners = 0; + this.CustomLabelSettingUnsetDns2.Size = new System.Drawing.Size(65, 15); + this.CustomLabelSettingUnsetDns2.TabIndex = 3; + this.CustomLabelSettingUnsetDns2.Text = "Secondary:"; + // + // CustomLabelSettingUnsetDns1 + // + this.CustomLabelSettingUnsetDns1.AutoSize = true; + this.CustomLabelSettingUnsetDns1.BackColor = System.Drawing.Color.DimGray; + this.CustomLabelSettingUnsetDns1.Border = false; + this.CustomLabelSettingUnsetDns1.BorderColor = System.Drawing.Color.Blue; + this.CustomLabelSettingUnsetDns1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.CustomLabelSettingUnsetDns1.ForeColor = System.Drawing.Color.White; + this.CustomLabelSettingUnsetDns1.Location = new System.Drawing.Point(110, 95); + this.CustomLabelSettingUnsetDns1.Name = "CustomLabelSettingUnsetDns1"; + this.CustomLabelSettingUnsetDns1.RoundedCorners = 0; + this.CustomLabelSettingUnsetDns1.Size = new System.Drawing.Size(51, 15); + this.CustomLabelSettingUnsetDns1.TabIndex = 2; + this.CustomLabelSettingUnsetDns1.Text = "Primary:"; + // + // CustomRadioButtonSettingUnsetDnsToStatic + // + this.CustomRadioButtonSettingUnsetDnsToStatic.BackColor = System.Drawing.Color.DimGray; + this.CustomRadioButtonSettingUnsetDnsToStatic.BorderColor = System.Drawing.Color.Blue; + this.CustomRadioButtonSettingUnsetDnsToStatic.CheckColor = System.Drawing.Color.Blue; + this.CustomRadioButtonSettingUnsetDnsToStatic.Checked = true; + this.CustomRadioButtonSettingUnsetDnsToStatic.ForeColor = System.Drawing.Color.White; + this.CustomRadioButtonSettingUnsetDnsToStatic.Location = new System.Drawing.Point(50, 65); + this.CustomRadioButtonSettingUnsetDnsToStatic.Name = "CustomRadioButtonSettingUnsetDnsToStatic"; + this.CustomRadioButtonSettingUnsetDnsToStatic.SelectionColor = System.Drawing.Color.LightBlue; + this.CustomRadioButtonSettingUnsetDnsToStatic.Size = new System.Drawing.Size(131, 17); + this.CustomRadioButtonSettingUnsetDnsToStatic.TabIndex = 1; + this.CustomRadioButtonSettingUnsetDnsToStatic.TabStop = true; + this.CustomRadioButtonSettingUnsetDnsToStatic.Text = "Unset DNS to Static."; + this.CustomRadioButtonSettingUnsetDnsToStatic.UseVisualStyleBackColor = false; + // + // CustomRadioButtonSettingUnsetDnsToDhcp + // + this.CustomRadioButtonSettingUnsetDnsToDhcp.BackColor = System.Drawing.Color.DimGray; + this.CustomRadioButtonSettingUnsetDnsToDhcp.BorderColor = System.Drawing.Color.Blue; + this.CustomRadioButtonSettingUnsetDnsToDhcp.CheckColor = System.Drawing.Color.Blue; + this.CustomRadioButtonSettingUnsetDnsToDhcp.ForeColor = System.Drawing.Color.White; + this.CustomRadioButtonSettingUnsetDnsToDhcp.Location = new System.Drawing.Point(50, 30); + this.CustomRadioButtonSettingUnsetDnsToDhcp.Name = "CustomRadioButtonSettingUnsetDnsToDhcp"; + this.CustomRadioButtonSettingUnsetDnsToDhcp.SelectionColor = System.Drawing.Color.LightBlue; + this.CustomRadioButtonSettingUnsetDnsToDhcp.Size = new System.Drawing.Size(130, 17); + this.CustomRadioButtonSettingUnsetDnsToDhcp.TabIndex = 0; + this.CustomRadioButtonSettingUnsetDnsToDhcp.Text = "Unset DNS to DHCP"; + this.CustomRadioButtonSettingUnsetDnsToDhcp.UseVisualStyleBackColor = false; + // // TabPageSettingsCPU // this.TabPageSettingsCPU.BackColor = System.Drawing.Color.Transparent; @@ -2290,7 +2524,7 @@ private void InitializeComponent() this.TabPageSettingsCPU.Padding = new System.Windows.Forms.Padding(3); this.TabPageSettingsCPU.Size = new System.Drawing.Size(590, 270); this.TabPageSettingsCPU.TabIndex = 1; - this.TabPageSettingsCPU.Tag = 3; + this.TabPageSettingsCPU.Tag = 4; this.TabPageSettingsCPU.Text = "CPU"; // // CustomRadioButtonSettingCPULow @@ -2399,7 +2633,7 @@ private void InitializeComponent() this.TabPageSettingsOthers.Padding = new System.Windows.Forms.Padding(3); this.TabPageSettingsOthers.Size = new System.Drawing.Size(590, 270); this.TabPageSettingsOthers.TabIndex = 2; - this.TabPageSettingsOthers.Tag = 4; + this.TabPageSettingsOthers.Tag = 5; this.TabPageSettingsOthers.Text = "Others"; // // CustomNumericUpDownSettingFallbackDnsPort @@ -3123,9 +3357,10 @@ private void InitializeComponent() this.TabPageSetDNS.PerformLayout(); this.TabPageShare.ResumeLayout(false); this.TabPageShare.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownHTTPProxyDataLength)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownHTTPProxyFragmentSize)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownHTTPProxyDivideBy)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownPDpiFragDelay)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownPDpiDataLength)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownPDpiFragmentSize)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownPDpiFragmentChunks)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownHTTPProxyPort)).EndInit(); this.TabPageDPI.ResumeLayout(false); this.CustomTabControlDPIBasicAdvanced.ResumeLayout(false); @@ -3151,6 +3386,8 @@ private void InitializeComponent() this.TabPageSettingsConnect.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownSettingCamouflagePort)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.CustomNumericUpDownSettingMaxServers)).EndInit(); + this.TabPageSettingsSetUnsetDNS.ResumeLayout(false); + this.TabPageSettingsSetUnsetDNS.PerformLayout(); this.TabPageSettingsCPU.ResumeLayout(false); this.TabPageSettingsCPU.PerformLayout(); this.TabPageSettingsOthers.ResumeLayout(false); @@ -3311,9 +3548,9 @@ private void InitializeComponent() private CustomControls.CustomLabel CustomLabelHTTPProxyPort; private CustomControls.CustomLabel CustomLabelShareInfo; private CustomControls.CustomButton CustomButtonShare; - private CustomControls.CustomCheckBox CustomCheckBoxHTTPProxyEnableDpiBypass; - private CustomControls.CustomLabel CustomLabelHTTPProxyDpiInfo3; - private CustomControls.CustomNumericUpDown CustomNumericUpDownHTTPProxyDivideBy; + private CustomControls.CustomCheckBox CustomCheckBoxPDpiEnableDpiBypass; + private CustomControls.CustomLabel CustomLabelPDpiDpiInfo3; + private CustomControls.CustomNumericUpDown CustomNumericUpDownPDpiFragmentChunks; private CustomControls.CustomLabel CustomLabelSettingBootstrapDnsPort; private CustomControls.CustomNumericUpDown CustomNumericUpDownSettingBootstrapDnsPort; private CustomControls.CustomNumericUpDown CustomNumericUpDownSettingFallbackDnsPort; @@ -3326,13 +3563,26 @@ private void InitializeComponent() private CustomControls.CustomCheckBox CustomCheckBoxHTTPProxyEventShowRequest; private CustomControls.CustomLabel CustomLabelShareSeparator1; private CustomControls.CustomButton CustomButtonToggleLogView; - private CustomControls.CustomNumericUpDown CustomNumericUpDownHTTPProxyFragmentSize; - private CustomControls.CustomLabel CustomLabelHTTPProxyDpiInfo2; - private CustomControls.CustomNumericUpDown CustomNumericUpDownHTTPProxyDataLength; - private CustomControls.CustomLabel CustomLabelHTTPProxyDpiInfo1; + private CustomControls.CustomNumericUpDown CustomNumericUpDownPDpiFragmentSize; + private CustomControls.CustomLabel CustomLabelPDpiDpiInfo2; + private CustomControls.CustomNumericUpDown CustomNumericUpDownPDpiDataLength; + private CustomControls.CustomLabel CustomLabelPDpiDpiInfo1; private CustomControls.CustomButton CustomButtonSetProxy; private CustomControls.CustomRichTextBox CustomRichTextBoxStatusIsProxySet; private ToolStripStatusLabel ToolStripStatusLabelDnsLatency; private ToolStripStatusLabel ToolStripStatusLabelDohLatency; + private CustomControls.CustomCheckBox CustomCheckBoxPDpiFragModeRandom; + private CustomControls.CustomCheckBox CustomCheckBoxPDpiDontChunkBigData; + private CustomControls.CustomLabel CustomLabelPDpiFragDelay; + private CustomControls.CustomNumericUpDown CustomNumericUpDownPDpiFragDelay; + private TabPage TabPageSettingsSetUnsetDNS; + private CustomControls.CustomRadioButton CustomRadioButtonSettingUnsetDnsToDhcp; + private CustomControls.CustomRadioButton CustomRadioButtonSettingUnsetDnsToStatic; + private CustomControls.CustomLabel CustomLabelSettingUnsetDns2; + private CustomControls.CustomLabel CustomLabelSettingUnsetDns1; + private CustomControls.CustomTextBox CustomTextBoxSettingUnsetDns2; + private CustomControls.CustomTextBox CustomTextBoxSettingUnsetDns1; + private CustomControls.CustomButton CustomButtonPDpiApplyChanges; + private CustomControls.CustomCheckBox CustomCheckBoxHTTPProxyEventShowChunkDetails; } } \ No newline at end of file diff --git a/SecureDNSClient/Forms/FormMain.cs b/SecureDNSClient/Forms/FormMain.cs index 216abda..3881528 100644 --- a/SecureDNSClient/Forms/FormMain.cs +++ b/SecureDNSClient/Forms/FormMain.cs @@ -38,6 +38,7 @@ public partial class FormMain : Form public Settings AppSettings; private ToolStripMenuItem ToolStripMenuItemIcon = new(); private HTTPProxyServer? HTTPProxy; + public static HTTPProxyServer.DPIBypassProgram DPIBypassProgram { get; private set; } = new(); private bool AudioAlertOnline = true; private bool AudioAlertOffline = false; private readonly Stopwatch CheckDPIWorksStopWatch = new(); @@ -90,7 +91,7 @@ public FormMain() CustomButtonViewWorkingServers.SetToolTip("Info", msgViewCustomServers); string msgFragmentChunks = "More chunks means more CPU usage."; - CustomNumericUpDownHTTPProxyDivideBy.SetToolTip("Warning", msgFragmentChunks); + CustomNumericUpDownPDpiFragmentChunks.SetToolTip("Warning", msgFragmentChunks); // Add Tooltips to advanced DPI string msgP = "Block passive DPI."; @@ -193,10 +194,14 @@ private void DefaultSettings() // Share CustomNumericUpDownHTTPProxyPort.Value = (decimal)8080; CustomCheckBoxHTTPProxyEventShowRequest.Checked = false; - CustomCheckBoxHTTPProxyEnableDpiBypass.Checked = true; - CustomNumericUpDownHTTPProxyDataLength.Value = (decimal)60; - CustomNumericUpDownHTTPProxyFragmentSize.Value = (decimal)2; - CustomNumericUpDownHTTPProxyDivideBy.Value = (decimal)60; + CustomCheckBoxHTTPProxyEventShowChunkDetails.Checked = false; + CustomCheckBoxPDpiEnableDpiBypass.Checked = true; + CustomNumericUpDownPDpiDataLength.Value = (decimal)60; + CustomNumericUpDownPDpiFragmentSize.Value = (decimal)2; + CustomNumericUpDownPDpiFragmentChunks.Value = (decimal)60; + CustomCheckBoxPDpiFragModeRandom.Checked = false; + CustomCheckBoxPDpiDontChunkBigData.Checked = false; + CustomNumericUpDownPDpiFragDelay.Value = (decimal)0; // DPI Basic CustomRadioButtonDPIMode1.Checked = false; @@ -259,6 +264,12 @@ private void DefaultSettings() CustomNumericUpDownSettingMaxServers.Value = (decimal)5; CustomNumericUpDownSettingCamouflagePort.Value = (decimal)5380; + // Settings Set/Unset DNS + CustomRadioButtonSettingUnsetDnsToDhcp.Checked = false; + CustomRadioButtonSettingUnsetDnsToStatic.Checked = true; + CustomTextBoxSettingUnsetDns1.Text = "8.8.8.8"; + CustomTextBoxSettingUnsetDns2.Text = "8.8.4.4"; + // Settings CPU CustomRadioButtonSettingCPUHigh.Checked = false; CustomRadioButtonSettingCPUAboveNormal.Checked = false; @@ -364,11 +375,13 @@ private void UpdateBools() IsDoHConnected = IsConnected; LocalDnsLatency = -1; LocalDohLatency = -1; + if (CamouflageDNSServer != null && CamouflageDNSServer.IsRunning) + CamouflageDNSServer.Stop(); if (IsDNSSet) UnsetSavedDNS(); } // Update bool IsDnsSet - IsDNSSet = UpdateBoolIsDnsSet(out bool _); + //IsDNSSet = UpdateBoolIsDnsSet(out bool _); // I need to test this on Win7 myself! // Update bool IsHTTPProxyRunning if (HTTPProxy != null) @@ -466,7 +479,7 @@ private bool UpdateBoolIsDnsSet(out bool isAnotherDnsSet) NetworkInterface? nic = Network.GetNICByName(nicName); if (nic != null) { - bool isDnsSet = Network.IsDnsSet(nic, out string dnsServer1, out string dnsServer2); + bool isDnsSet = Network.IsDnsSet(nic, out string dnsServer1, out string _); if (!isDnsSet) return false; // DNS is set to DHCP else { @@ -649,10 +662,10 @@ private void FlushDNS() private void FlushDnsOnExit() { - ProcessManager.ExecuteOnly("ipconfig", "/flushdns"); - ProcessManager.ExecuteOnly("ipconfig", "/registerdns"); - ProcessManager.ExecuteOnly("ipconfig", "/release"); - ProcessManager.ExecuteOnly("ipconfig", "/renew"); + ProcessManager.Execute("ipconfig", "/flushdns", true, true); + ProcessManager.Execute("ipconfig", "/registerdns", true, true); + ProcessManager.Execute("ipconfig", "/release", true, true); + ProcessManager.ExecuteOnly("ipconfig", "/renew", true, true); //ProcessManager.Execute("netsh", "winsock reset"); // Needs PC Restart } @@ -666,10 +679,29 @@ private void KillAll() ProcessManager.KillProcessByName("dnscrypt-proxy"); if (ProcessManager.FindProcessByName("goodbyedpi")) ProcessManager.KillProcessByName("goodbyedpi"); + // Unset DNS UnsetSavedDNS(); } private void UnsetSavedDNS() + { + bool unsetToDHCP = CustomRadioButtonSettingUnsetDnsToDhcp.Checked; + if (unsetToDHCP) + { + // Unset to DHCP + UnsetSavedDnsDHCP(); + } + else + { + // Unset to Static + string dns1 = CustomTextBoxSettingUnsetDns1.Text; + string dns2 = CustomTextBoxSettingUnsetDns2.Text; + UnsetSavedDnsStatic(dns1, dns2); + } + } + + // Unset to DHCP + private void UnsetSavedDnsDHCP() { if (File.Exists(SecureDNS.NicNamePath)) { @@ -686,6 +718,24 @@ private void UnsetSavedDNS() } } + // Unset to Static + private void UnsetSavedDnsStatic(string dns1, string dns2) + { + if (File.Exists(SecureDNS.NicNamePath)) + { + string nicName = File.ReadAllText(SecureDNS.NicNamePath).Replace(NL, string.Empty); + if (nicName.Length > 0) + { + NetworkInterface? nic = Network.GetNICByName(nicName); + if (nic != null) + { + Network.UnsetDNS(nic, dns1, dns2); + IsDNSSet = false; + } + } + } + } + private ProcessPriorityClass GetCPUPriority() { if (CustomRadioButtonSettingCPUHigh.Checked) @@ -977,7 +1027,7 @@ private async Task CheckServers() // SDNS DNSCryptStampReader? dnsCryptStampReader = null; - if (dns.StartsWith("sdns://")) + if (dns.ToLower().StartsWith("sdns://")) { // Decode Stamp dnsCryptStampReader = new(dns); @@ -1364,7 +1414,7 @@ private void ConnectDNSProxy() // Sort by latency if (WorkingDnsList.Count > 1) - WorkingDnsList = WorkingDnsList.OrderByDescending(t => t.Item1).ToList(); + WorkingDnsList = WorkingDnsList.OrderBy(t => t.Item1).ToList(); // Get number of max servers int maxServers = decimal.ToInt32(CustomNumericUpDownSettingMaxServers.Value); @@ -1378,7 +1428,7 @@ private void ConnectDNSProxy() Tuple latencyHost = WorkingDnsList[n]; long latency = latencyHost.Item1; string host = latencyHost.Item2; - + hosts += " -u " + host; theDll.WriteLine(host); @@ -1447,23 +1497,18 @@ void proxySchemeIncorrect() this.InvokeIt(() => CustomRichTextBoxLog.AppendText(msgWrongProxy + NL, Color.IndianRed)); } - // Check if proxy scheme is correct 1 + // Check if proxy scheme is correct if (string.IsNullOrWhiteSpace(proxyScheme) || !proxyScheme.Contains("//") || proxyScheme.EndsWith('/')) { proxySchemeIncorrect(); return; } - // Check if proxy scheme is correct 2 - Uri? uri = Network.UrlToUri(proxyScheme); - if (uri == null) - { - proxySchemeIncorrect(); - return; - } + // Get Host and Port of Proxy + string host = Network.UrlToHostAndPort(proxyScheme, 0, out int port); // Check if proxy works - bool canPing = Network.CanPing(uri.Host, uri.Port, 15); + bool canPing = Network.CanPing(host, port, 15); if (!canPing) { string msgWrongProxy = "Proxy doesn't work."; @@ -1943,7 +1988,7 @@ private async void SetDNS() { string msgConnect = string.Empty; if (!IsDoHConnected) - msgConnect = "Connect first." + NL; + msgConnect = "Wait until DNS gets online." + NL; else msgConnect = "Activate legacy DNS Server first." + NL; this.InvokeIt(() => CustomRichTextBoxLog.AppendText(msgConnect, Color.IndianRed)); @@ -1966,8 +2011,6 @@ private async void SetDNS() } // Set DNS - Network.UnsetDNS(nic); // Unset first - Task.Delay(200).Wait(); // Wait a moment Network.SetDNS(nic, dnss); // Set DNS IsDNSSet = true; @@ -2003,9 +2046,24 @@ private async void SetDNS() else { // Unset DNS - Network.UnsetDNS(nic); - Task.Delay(200).Wait(); - UnsetSavedDNS(); + bool unsetToDHCP = CustomRadioButtonSettingUnsetDnsToDhcp.Checked; + if (unsetToDHCP) + { + // Unset to DHCP + Network.UnsetDNS(nic); + Task.Delay(200).Wait(); + UnsetSavedDnsDHCP(); + } + else + { + // Unset to Static + string dns1 = CustomTextBoxSettingUnsetDns1.Text; + string dns2 = CustomTextBoxSettingUnsetDns2.Text; + Network.UnsetDNS(nic, dns1, dns2); + Task.Delay(200).Wait(); + UnsetSavedDnsStatic(dns1, dns2); + } + IsDNSSet = false; // Flush DNS @@ -2059,20 +2117,12 @@ private void Share() { HTTPProxy.OnRequestReceived -= HTTPProxy_OnRequestReceived; HTTPProxy.OnRequestReceived += HTTPProxy_OnRequestReceived; + HTTPProxy.OnChunkDetailsReceived -= HTTPProxy_OnChunkDetailsReceived; + HTTPProxy.OnChunkDetailsReceived += HTTPProxy_OnChunkDetailsReceived; HTTPProxy.OnErrorOccurred -= HTTPProxy_OnErrorOccurred; HTTPProxy.OnErrorOccurred += HTTPProxy_OnErrorOccurred; - // Get fragment settings - bool enableDpiBypass = CustomCheckBoxHTTPProxyEnableDpiBypass.Checked; - int dataLength = int.Parse(CustomNumericUpDownHTTPProxyDataLength.Value.ToString()); - int fragmentSize = int.Parse(CustomNumericUpDownHTTPProxyFragmentSize.Value.ToString()); - int divideBy = int.Parse(CustomNumericUpDownHTTPProxyDivideBy.Value.ToString()); - - if (enableDpiBypass) - { - HTTPProxy.EnableDpiBypassProgram(DPIBypass.Mode.Program, dataLength, fragmentSize, divideBy); - IsDPIActive = true; - } + ApplyPDpiChanges(); HTTPProxy.Start(IPAddress.Any, SettingsWindow.GetHTTPProxyPort(CustomNumericUpDownHTTPProxyPort), 100); Task.Delay(500).Wait(); @@ -2105,6 +2155,18 @@ void HTTPProxy_OnRequestReceived(object? sender, EventArgs e) } } + void HTTPProxy_OnChunkDetailsReceived(object? sender, EventArgs e) + { + if (sender is string msg) + { + if (CustomCheckBoxHTTPProxyEventShowChunkDetails.Checked) + { + msg += NL; // Adding an additional line break. + this.InvokeIt(() => CustomRichTextBoxLog.AppendText(msg, Color.Gray)); + } + } + } + // Proxy Event Errors void HTTPProxy_OnErrorOccurred(object? sender, EventArgs e) { @@ -2228,7 +2290,7 @@ private async void SetProxy() CustomRichTextBoxLog.AppendText(msg3 + NL, Color.LightGray); // Check DPI Works - if (CustomCheckBoxHTTPProxyEnableDpiBypass.Checked) + if (CustomCheckBoxPDpiEnableDpiBypass.Checked) { // Get and check blocked domain is valid bool isBlockedDomainValid = SecureDNS.IsBlockedDomainValid(CustomTextBoxSettingCheckDPIHost, CustomRichTextBoxLog, out string blockedDomain); @@ -2270,6 +2332,40 @@ private async void SetProxy() } } + private async void ApplyPDpiChanges() + { + if (HTTPProxy != null) + { + // Get fragment settings + bool enableDpiBypass = CustomCheckBoxPDpiEnableDpiBypass.Checked; + int dataLength = int.Parse(CustomNumericUpDownPDpiDataLength.Value.ToString()); + int fragmentSize = int.Parse(CustomNumericUpDownPDpiFragmentSize.Value.ToString()); + int fragmentChunks = int.Parse(CustomNumericUpDownPDpiFragmentChunks.Value.ToString()); + bool randomMode = CustomCheckBoxPDpiFragModeRandom.Checked; + bool dontChunkBigdata = CustomCheckBoxPDpiDontChunkBigData.Checked; + int fragmentDelay = int.Parse(CustomNumericUpDownPDpiFragDelay.Value.ToString()); + + DPIBypass.Mode bypassMode = enableDpiBypass ? DPIBypass.Mode.Program : DPIBypass.Mode.Disable; + IsDPIActive = DPIBypassProgram.DPIBypassMode == DPIBypass.Mode.Program; + + DPIBypassProgram.Set(bypassMode, dataLength, fragmentSize, fragmentChunks, fragmentDelay); + DPIBypassProgram.DontChunkTheBiggestRequest = dontChunkBigdata; + DPIBypassProgram.SendInRandom = randomMode; + HTTPProxy.EnableDPIBypass(DPIBypassProgram); + + // Check DPI Works + if (CustomCheckBoxPDpiEnableDpiBypass.Checked && HTTPProxy.IsRunning) + { + IsDPIActive = true; + Task.Delay(100).Wait(); + // Get and check blocked domain is valid + bool isBlockedDomainValid = SecureDNS.IsBlockedDomainValid(CustomTextBoxSettingCheckDPIHost, CustomRichTextBoxLog, out string blockedDomain); + if (isBlockedDomainValid) + await CheckDPIWorks(blockedDomain); + } + } + } + //============================== DPI private async void DPIBasic() @@ -2815,7 +2911,7 @@ private void CustomButtonCheck_Click(object? sender, EventArgs? e) if (IsDNSSet) SetDNS(); // Unset DNS else - UnsetSavedDNS(); // Unset Saved DNS + UnsetSavedDNS(); } try @@ -3097,6 +3193,11 @@ private void CustomButtonSetProxy_Click(object sender, EventArgs e) SetProxy(); } + private void CustomButtonPDpiApplyChanges_Click(object sender, EventArgs e) + { + ApplyPDpiChanges(); + } + private void CustomButtonRestoreDefault_Click(object sender, EventArgs e) { if (IsCheckingStarted) diff --git a/SecureDNSClient/MsmhTools/HTTPProxyServer/DPIBypass.cs b/SecureDNSClient/MsmhTools/HTTPProxyServer/DPIBypass.cs index 0c69564..74a4277 100644 --- a/SecureDNSClient/MsmhTools/HTTPProxyServer/DPIBypass.cs +++ b/SecureDNSClient/MsmhTools/HTTPProxyServer/DPIBypass.cs @@ -8,10 +8,10 @@ namespace MsmhTools.HTTPProxyServer public class DPIBypass { // Max Data Length = 65536 + private readonly int MaxDataLength = 65536; public enum Mode { Program, - Random, Disable } @@ -19,43 +19,67 @@ public class ProgramMode : DPIBypass { private byte[] Data; private Socket Socket; + + /// + /// Don't chunk the request when size is 65536. + /// + public bool DontChunkTheBiggestRequest { get; set; } = false; + + public bool SendInRandom { get; set; } = false; + + public event EventHandler? OnChunkDetailsReceived; + public ProgramMode(byte[] data, Socket socket) { Data = data; Socket = socket; } - public void Send(int firstPartOfDataLength, int programFragmentSize, int divideBy, int fragmentDelay = 0) + public void Send(int firstPartOfDataLength, int fragmentSize, int fragmentChunks, int fragmentDelay = 0) { - int fragmentSize; - if (Data.Length < firstPartOfDataLength) - fragmentSize = programFragmentSize; - else - fragmentSize = Data.Length / divideBy; + if (!SendInRandom) + { + int fragmentSizeOut; + if (Data.Length <= firstPartOfDataLength) + fragmentSizeOut = Math.Min(fragmentSize, Data.Length); + else + fragmentSizeOut = Data.Length / fragmentChunks; - SendDataInNormalFragment1(Data, Socket, fragmentSize, fragmentDelay); - } - } + if (fragmentSizeOut == 0) fragmentSizeOut = 1; + if (fragmentSizeOut > MaxDataLength) fragmentSizeOut = MaxDataLength; - public class RandomMode : DPIBypass - { - private byte[] Data; - private Socket Socket; - public RandomMode(byte[] data, Socket socket) - { - Data = data; - Socket = socket; - } + if (DontChunkTheBiggestRequest) + if (Data.Length == MaxDataLength) fragmentSizeOut = MaxDataLength; - public void Send(int fragmentLength, int fragmentDelay = 0) - { - SendDataInRandomFragment(Data, Socket, fragmentLength, fragmentDelay); + SendDataInNormalFragment1(Data, Socket, fragmentSizeOut, fragmentDelay, OnChunkDetailsReceived); + } + else + { + if (Data.Length <= firstPartOfDataLength) + { + int fragmentSizeOut = Math.Min(fragmentSize, Data.Length); + SendDataInNormalFragment1(Data, Socket, fragmentSizeOut, fragmentDelay, OnChunkDetailsReceived); + } + else + { + int offset = 5; + Random random = new(); + fragmentChunks = random.Next(fragmentChunks - offset, fragmentChunks + offset); + + if (fragmentChunks == 0) fragmentChunks = 1; + if (fragmentChunks > Data.Length) fragmentChunks = Data.Length; + + SendDataInRandomFragment(Data, Socket, fragmentChunks, fragmentDelay, OnChunkDetailsReceived); + } + } } } - private static void SendDataInNormalFragment1(byte[] data, Socket socket, int fragmentSize, int fragmentDelay) + private static void SendDataInNormalFragment1(byte[] data, Socket socket, int fragmentSize, int fragmentDelay, EventHandler? onChunkDetailsReceived) { - // Send data + // Create packets + List packets = new(); + packets.Clear(); int prevIndex = 0; for (int n = 0; n < data.Length; n += fragmentSize) { @@ -65,6 +89,23 @@ private static void SendDataInNormalFragment1(byte[] data, Socket socket, int fr byte[] fragmentData = new byte[fragmentSize]; prevIndex = n; Buffer.BlockCopy(data, n, fragmentData, 0, fragmentSize); + packets.Add(fragmentData); + } + catch (Exception ex) + { + packets.Clear(); + string msgEvent = $"Error, Creating normal packets: {ex.Message}"; + Console.WriteLine(msgEvent); + return; + } + } + + // Send packets + for (int i = 0; i < packets.Count; i++) + { + try + { + byte[] fragmentData = packets[i]; if (socket == null) return; socket.Send(fragmentData); if (fragmentDelay > 0) @@ -77,9 +118,12 @@ private static void SendDataInNormalFragment1(byte[] data, Socket socket, int fr return; } } - + + string chunkDetailsEvent = $"Length: {data.Length}, Chunks: {packets.Count}"; + onChunkDetailsReceived?.Invoke(chunkDetailsEvent, EventArgs.Empty); + int outLength = prevIndex + fragmentSize; - Debug.WriteLine($"{outLength} = {data.Length}"); + Debug.WriteLine($"{outLength} = {data.Length}, Chunks: {packets.Count}"); } private static void SendDataInNormalFragment2(byte[] data, Socket socket, int fragmentSize, int fragmentDelay) @@ -138,13 +182,19 @@ private static void SendDataInNormalFragment3(byte[] data, Socket socket, int fr Debug.WriteLine($"{outLength} = {data.Length}"); } - private static void SendDataInRandomFragment(byte[] data, Socket socket, int fragmentLength, int fragmentDelay) + private static void SendDataInRandomFragment(byte[] data, Socket socket, int fragmentChunks, int fragmentDelay, EventHandler? onChunkDetailsReceived) { - // Send data - fragmentLength = Math.Min(fragmentLength, data.Length); - List indices = GenerateRandomIndices(1, data.Length - 1, fragmentLength - 1); + // Create packets + List packets = new(); + packets.Clear(); + fragmentChunks = Math.Min(fragmentChunks, data.Length); + List indices; + if (fragmentChunks < data.Length) + indices = GenerateRandomIndices(1, data.Length - 1, fragmentChunks - 1); + else + indices = Enumerable.Range(0, data.Length - 1).ToList(); indices.Sort(); - + int prevIndex = 0; for (int n = 0; n < indices.Count; n++) { @@ -153,15 +203,13 @@ private static void SendDataInRandomFragment(byte[] data, Socket socket, int fra int index = indices[n]; byte[] fragmentData = new byte[index - prevIndex]; Buffer.BlockCopy(data, prevIndex, fragmentData, 0, fragmentData.Length); + packets.Add(fragmentData); prevIndex = index; - if (socket == null) return; - socket.Send(fragmentData); - if (fragmentDelay > 0) - Task.Delay(fragmentDelay).Wait(); } catch (Exception ex) { - string msgEvent = $"Error, SendDataInRandomFragment: {ex.Message}"; + packets.Clear(); + string msgEvent = $"Error, Creating random packets: {ex.Message}"; Console.WriteLine(msgEvent); return; } @@ -171,17 +219,39 @@ private static void SendDataInRandomFragment(byte[] data, Socket socket, int fra { byte[] lastFragmentData = new byte[data.Length - prevIndex]; Buffer.BlockCopy(data, prevIndex, lastFragmentData, 0, lastFragmentData.Length); - if (socket == null) return; - socket.Send(lastFragmentData); + packets.Add(lastFragmentData); int outLength = prevIndex + lastFragmentData.Length; - Debug.WriteLine($"{outLength} = {data.Length}"); + Debug.WriteLine($"{outLength} = {data.Length}, Chunks: {packets.Count}"); } catch (Exception ex) { - string msgEvent = $"Error, SendDataInRandomFragment Last Fragment: {ex.Message}"; + packets.Clear(); + string msgEvent = $"Error, Creating last random packet: {ex.Message}"; Console.WriteLine(msgEvent); } + + // Send packets + for (int i = 0; i < packets.Count; i++) + { + try + { + byte[] fragmentData = packets[i]; + if (socket == null) return; + socket.Send(fragmentData); + if (fragmentDelay > 0) + Task.Delay(fragmentDelay).Wait(); + } + catch (Exception ex) + { + string msgEvent = $"Error, SendDataInRandomFragment: {ex.Message}"; + Console.WriteLine(msgEvent); + return; + } + } + + string chunkDetailsEvent = $"Length: {data.Length}, Chunks: {packets.Count}"; + onChunkDetailsReceived?.Invoke(chunkDetailsEvent, EventArgs.Empty); } private static List GenerateRandomIndices(int minValue, int maxValue, int count) diff --git a/SecureDNSClient/MsmhTools/HTTPProxyServer/HTTPProxyServer.cs b/SecureDNSClient/MsmhTools/HTTPProxyServer/HTTPProxyServer.cs index 4871922..cb74563 100644 --- a/SecureDNSClient/MsmhTools/HTTPProxyServer/HTTPProxyServer.cs +++ b/SecureDNSClient/MsmhTools/HTTPProxyServer/HTTPProxyServer.cs @@ -10,6 +10,39 @@ namespace MsmhTools.HTTPProxyServer { public class HTTPProxyServer { + public static DPIBypassProgram BypassProgram = new(); + public void EnableDPIBypass(DPIBypassProgram dpiBypassProgram) + { + BypassProgram = dpiBypassProgram; + } + + public class DPIBypassProgram : HTTPProxyServer + { + public DPIBypass.Mode DPIBypassMode { get; set; } = DPIBypass.Mode.Disable; + public int FirstPartOfDataLength { get; set; } = 0; + public int FragmentSize { get; set; } = 0; + public int FragmentChunks { get; set; } = 0; + public int FragmentDelay { get; set; } = 0; + /// + /// Don't chunk the request when size is 65536. + /// + public bool DontChunkTheBiggestRequest { get; set; } = false; + public bool SendInRandom { get; set; } = false; + public DPIBypassProgram() + { + + } + + public void Set(DPIBypass.Mode mode, int firstPartOfDataLength, int fragmentSize, int fragmentChunks, int fragmentDelay) + { + DPIBypassMode = mode; + FirstPartOfDataLength = firstPartOfDataLength; + FragmentSize = fragmentSize; + FragmentChunks = fragmentChunks; + FragmentDelay = fragmentDelay; + } + } + private static ProxySettings _Settings = new(); private static TunnelManager? _TunnelManager; @@ -23,16 +56,11 @@ public class HTTPProxyServer private static bool Cancel = false; public static readonly int MaxDataSize = 65536; - private DPIBypass.Mode DpiBypassMode = DPIBypass.Mode.Disable; - private int FirstPartOfDataLength = 100; - private int ProgramFragmentSize = 1; - private int DivideBy = 100; - private int FragmentLength = 7; - private int FragmentDelay = 0; public event EventHandler? OnRequestReceived; public event EventHandler? OnErrorOccurred; public event EventHandler? OnDebugInfoReceived; + public event EventHandler? OnChunkDetailsReceived; private static readonly EventWaitHandle Terminator = new(false, EventResetMode.ManualReset); public HTTPProxyServer() @@ -60,6 +88,7 @@ public void Start(IPAddress ipAddress, int port, int maxThreads) _CancelToken = _CancelTokenSource.Token; Cancel = false; + Tunnel.Cancel = false; Task.Run(() => AcceptConnections(), _CancelToken); @@ -76,7 +105,19 @@ public void Stop() Terminator.Set(); _CancelTokenSource.Cancel(true); Cancel = true; + Tunnel.Cancel = true; _TcpListener.Stop(); + + //if (_TunnelManager != null) + //{ + // var t = _TunnelManager.GetFull().ToList(); + // for (int n = 0; n < t.Count; n++) + // { + // var kvp = t[n]; + // _TunnelManager.Remove(kvp.Key); + // } + //} + IsRunning = _TcpListener.Server.IsBound; Goodbye(); } @@ -89,7 +130,7 @@ public int ListeningPort public bool IsDpiActive { - get => DpiBypassMode != DPIBypass.Mode.Disable; + get => BypassProgram.DPIBypassMode != DPIBypass.Mode.Disable; } public Dictionary GetCurrentConnectTunnels() @@ -115,28 +156,14 @@ private void Goodbye() OnDebugInfoReceived?.Invoke(msgEvent, EventArgs.Empty); } - public void EnableDpiBypassProgram(DPIBypass.Mode mode, int firstPartOfDataLength, int programFragmentSize, int divideBy, int fragmentDelay = 0) - { - DpiBypassMode = mode; - FirstPartOfDataLength = firstPartOfDataLength; - ProgramFragmentSize = programFragmentSize; - DivideBy = divideBy; - FragmentDelay = fragmentDelay; - } - - public void EnableDpiBypassRandom(DPIBypass.Mode mode, int fragmentLength, int fragmentDelay = 0) - { - DpiBypassMode = mode; - FragmentLength = fragmentLength; - FragmentDelay = fragmentDelay; - } - #endregion #region Connection-Handler private void AcceptConnections() { + if (Cancel) return; + try { _TcpListener = new(_Settings.ListenerIpAddress, _Settings.ListenerPort); @@ -173,6 +200,8 @@ private void AcceptConnections() private async Task ProcessConnection(TcpClient client) { + if (Cancel) return; + int connectionId = Environment.CurrentManagedThreadId; _ActiveThreads++; Debug.WriteLine($"Active Requests: {_ActiveThreads}"); @@ -204,7 +233,7 @@ private async Task ProcessConnection(TcpClient client) string serverIp = serverIpEndpoint != null ? serverIpEndpoint.Address.ToString() : string.Empty; int serverPort = serverIpEndpoint != null ? serverIpEndpoint.Port : 0; - Request req = Request.FromTcpClient(client); + Request? req = Request.FromTcpClient(client); if (req == null) { // Event Error @@ -220,13 +249,12 @@ private async Task ProcessConnection(TcpClient client) req.DestPort = serverPort; // Event - string msgEvent = $"{req.DestHostname}:{req.DestHostPort}"; - OnRequestReceived?.Invoke(msgEvent, EventArgs.Empty); + OnRequestReceived?.Invoke($"{req.DestHostname}:{req.DestHostPort}", EventArgs.Empty); if (req.Method == HttpMethod.CONNECT) { // Event - msgEvent = $"{clientEndpoint} proxying request via CONNECT to {req.FullUrl}"; + string msgEvent = $"{clientEndpoint} proxying request via CONNECT to {req.FullUrl}"; OnDebugInfoReceived?.Invoke(msgEvent, EventArgs.Empty); ConnectHttpsRequest(connectionId, client, req); @@ -234,7 +262,7 @@ private async Task ProcessConnection(TcpClient client) else { // Event - msgEvent = $"{clientEndpoint} proxying request to {req.FullUrl}"; + string msgEvent = $"{clientEndpoint} proxying request to {req.FullUrl}"; OnDebugInfoReceived?.Invoke(msgEvent, EventArgs.Empty); await ConnectHttpRequestAsync(req, client); @@ -259,6 +287,8 @@ private async Task ProcessConnection(TcpClient client) private void ConnectHttpsRequest(int connectionId, TcpClient client, Request req) { + if (Cancel) return; + Tunnel? currTunnel = null; TcpClient? server = null; @@ -267,7 +297,7 @@ private void ConnectHttpsRequest(int connectionId, TcpClient client, Request req client.NoDelay = true; client.Client.NoDelay = true; - server = new TcpClient(); + server = new(); try { @@ -311,7 +341,7 @@ static byte[] ConnectResponse() } // Create Tunnel - currTunnel = new Tunnel( + currTunnel = new( req.SourceIp, req.SourcePort, req.DestIp, @@ -321,14 +351,35 @@ static byte[] ConnectResponse() client, server); - // Pass the events - currTunnel.PassTheEvents(OnRequestReceived, OnErrorOccurred); + // Tunnel Event OnChunkDetailsReceived + currTunnel.OnChunkDetailsReceived -= CurrTunnel_OnChunkDetailsReceived; + currTunnel.OnChunkDetailsReceived += CurrTunnel_OnChunkDetailsReceived; + void CurrTunnel_OnChunkDetailsReceived(object? sender, EventArgs e) + { + if (sender is string chunkDetails) + { + string msgEvent = $"{req.DestHostname}:{req.DestHostPort} {chunkDetails}"; + OnChunkDetailsReceived?.Invoke(msgEvent, EventArgs.Empty); + } + } - // Pass DPI bypass - if (DpiBypassMode == DPIBypass.Mode.Program) - currTunnel.EnableDpiBypassProgram(DPIBypass.Mode.Program, FirstPartOfDataLength, ProgramFragmentSize, DivideBy, FragmentDelay); - else if (DpiBypassMode == DPIBypass.Mode.Random) - currTunnel.EnableDpiBypassRandom(DPIBypass.Mode.Random, FragmentLength, FragmentDelay); + // Tunnel Event OnDebugInfoReceived + currTunnel.OnDebugInfoReceived -= CurrTunnel_OnDebugInfoReceived; + currTunnel.OnDebugInfoReceived += CurrTunnel_OnDebugInfoReceived; + void CurrTunnel_OnDebugInfoReceived(object? sender, EventArgs e) + { + if (sender is string debugInfo) + OnDebugInfoReceived?.Invoke(debugInfo, EventArgs.Empty); + } + + // Tunnel Event OnErrorOccurred + currTunnel.OnErrorOccurred -= CurrTunnel_OnErrorOccurred; + currTunnel.OnErrorOccurred += CurrTunnel_OnErrorOccurred; + void CurrTunnel_OnErrorOccurred(object? sender, EventArgs e) + { + if (sender is string error) + OnErrorOccurred?.Invoke(error, EventArgs.Empty); + } if (_TunnelManager != null) _TunnelManager.Add(connectionId, currTunnel); @@ -365,6 +416,8 @@ static byte[] ConnectResponse() private async Task ConnectHttpRequestAsync(Request req, TcpClient tcpClient) { + if (Cancel) return; + RestResponse? resp = proxyRequest(req).Result; if (resp != null) { @@ -376,6 +429,8 @@ private async Task ConnectHttpRequestAsync(Request req, TcpClient tcpClient) async Task proxyRequest(Request request) { + if (Cancel) return null; + try { if (request.Headers != null) @@ -430,6 +485,8 @@ private async Task ConnectHttpRequestAsync(Request req, TcpClient tcpClient) async Task sendRestResponse(RestResponse resp, NetworkStream ns) { + if (Cancel) return; + try { byte[]? ret = Array.Empty(); diff --git a/SecureDNSClient/MsmhTools/HTTPProxyServer/Request.cs b/SecureDNSClient/MsmhTools/HTTPProxyServer/Request.cs index 5f13ddb..ccddeaf 100644 --- a/SecureDNSClient/MsmhTools/HTTPProxyServer/Request.cs +++ b/SecureDNSClient/MsmhTools/HTTPProxyServer/Request.cs @@ -1,14 +1,9 @@ using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; -using System.IO; -using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; -using System.Threading; -using System.Threading.Tasks; namespace MsmhTools.HTTPProxyServer { @@ -455,7 +450,7 @@ public Request(HttpListenerContext ctx, bool readStreamFully) /// /// TcpClient. /// A populated HttpRequest. - public static Request FromTcpClient(TcpClient client) + public static Request? FromTcpClient(TcpClient client) { if (client == null) throw new ArgumentNullException(nameof(client)); @@ -522,7 +517,10 @@ public static Request FromTcpClient(TcpClient client) // Process-Headers if (headerBytes == null || headerBytes.Length < 1) - throw new IOException("No header data read from the stream."); + { + //throw new IOException("No header data read from the stream."); + return null; + } ret = BuildHeaders(headerBytes); diff --git a/SecureDNSClient/MsmhTools/HTTPProxyServer/Tunnel.cs b/SecureDNSClient/MsmhTools/HTTPProxyServer/Tunnel.cs index c72a96d..7135356 100644 --- a/SecureDNSClient/MsmhTools/HTTPProxyServer/Tunnel.cs +++ b/SecureDNSClient/MsmhTools/HTTPProxyServer/Tunnel.cs @@ -1,12 +1,8 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; -using System.Text; -using System.Threading; -using System.Threading.Tasks; namespace MsmhTools.HTTPProxyServer { @@ -71,18 +67,11 @@ public class Tunnel : IDisposable public Stream ServerStream { get; set; } private bool _Active = true; - - private DPIBypass.Mode DpiBypassMode = DPIBypass.Mode.Disable; - private int FirstPartOfDataLength = 100; - private int ProgramFragmentSize = 1; - private int DivideBy = 100; - private int FragmentLength = 7; - private int FragmentDelay = 0; + public static bool Cancel { get; set; } = false; public event EventHandler? OnErrorOccurred; public event EventHandler? OnDebugInfoReceived; - - #region Constructors-and-Factories + public event EventHandler? OnChunkDetailsReceived; /// /// Construct a Tunnel object. @@ -146,45 +135,6 @@ public Tunnel( _Active = true; } - public void EnableDpiBypassProgram(DPIBypass.Mode mode, int firstPartOfDataLength, int programFragmentSize, int divideBy, int fragmentDelay = 0) - { - DpiBypassMode = mode; - FirstPartOfDataLength = firstPartOfDataLength; - ProgramFragmentSize = programFragmentSize; - DivideBy = divideBy; - FragmentDelay = fragmentDelay; - } - - public void EnableDpiBypassRandom(DPIBypass.Mode mode, int fragmentLength, int fragmentDelay = 0) - { - DpiBypassMode = mode; - FragmentLength = fragmentLength; - FragmentDelay = fragmentDelay; - } - - public void PassTheEvents(EventHandler? onRequestReceived = null, - EventHandler? onErrorOccurred = null, - EventHandler? onDebugInfoReceived = null) - { - OnErrorOccurred += Tunnel_OnErrorOccurred; - void Tunnel_OnErrorOccurred(object? sender, EventArgs e) - { - if (sender is string msg && onErrorOccurred != null) - onErrorOccurred?.Invoke(msg, EventArgs.Empty); - } - - OnDebugInfoReceived += Tunnel_OnDebugInfoReceived; - void Tunnel_OnDebugInfoReceived(object? sender, EventArgs e) - { - if (sender is string msg && onDebugInfoReceived != null) - onDebugInfoReceived?.Invoke(msg, EventArgs.Empty); - } - } - - #endregion - - #region Public-Methods - /// /// Human-readable string. /// @@ -218,6 +168,8 @@ public string Destination() /// True if both connections are active. public bool IsActive() { + if (Cancel) return false; + bool clientActive = false; bool serverActive = false; bool clientSocketActive = false; @@ -296,10 +248,6 @@ public void Dispose() Dispose(true); } - #endregion - - #region Private-Methods - protected virtual void Dispose(bool disposing) { if (ClientStream != null) @@ -324,6 +272,7 @@ protected virtual void Dispose(bool disposing) private bool StreamReadSync(TcpClient client, out byte[]? data) { data = null; + if (Cancel) return false; try { @@ -374,14 +323,17 @@ private bool StreamReadSync(TcpClient client, out byte[]? data) } finally { + } } private async Task StreamReadAsync(TcpClient client) { + if (Cancel) return null; try - { + { Stream stream = client.GetStream(); + if (stream == null) return null; byte[] buffer = new byte[65536]; using MemoryStream memStream = new(); @@ -424,11 +376,13 @@ private bool StreamReadSync(TcpClient client, out byte[]? data) } finally { + } } private TcpState GetTcpLocalState(TcpClient tcpClient) { + if (Cancel) return TcpState.Unknown; var state = IPGlobalProperties.GetIPGlobalProperties() .GetActiveTcpConnections() .FirstOrDefault(x => x.LocalEndPoint.Equals(tcpClient.Client.LocalEndPoint)); @@ -437,14 +391,19 @@ private TcpState GetTcpLocalState(TcpClient tcpClient) private TcpState GetTcpRemoteState(TcpClient tcpClient) { + if (tcpClient.Client == null || Cancel) + return TcpState.Unknown; + + Socket socket = tcpClient.Client; var state = IPGlobalProperties.GetIPGlobalProperties() - .GetActiveTcpConnections() - .FirstOrDefault(x => x.RemoteEndPoint.Equals(tcpClient.Client.RemoteEndPoint)); + .GetActiveTcpConnections() + .FirstOrDefault(x => x.RemoteEndPoint.Equals(socket.RemoteEndPoint)); return state != null ? state.State : TcpState.Unknown; } private void ClientReaderSync() { + if (Cancel) return; try { // Event @@ -499,6 +458,7 @@ private void ClientReaderSync() private void ServerReaderSync() { + if (Cancel) return; try { // Event @@ -553,6 +513,7 @@ private void ServerReaderSync() private async void ClientReaderAsync() { + if (Cancel) return; try { // Event @@ -597,6 +558,7 @@ private async void ClientReaderAsync() private async void ServerReaderAsync() { + if (Cancel) return; try { // Event @@ -651,23 +613,35 @@ private void ServerSend(byte[] data) private void Send(byte[] data, Socket? socket) { + if (Cancel) return; if (socket != null) { - if (DpiBypassMode == DPIBypass.Mode.Program) + HTTPProxyServer.DPIBypassProgram bp = HTTPProxyServer.BypassProgram; + if (bp.DPIBypassMode == DPIBypass.Mode.Program) { DPIBypass.ProgramMode programMode = new(data, socket); - programMode.Send(FirstPartOfDataLength, ProgramFragmentSize, DivideBy, FragmentDelay); - } - else if (DpiBypassMode == DPIBypass.Mode.Random) - { - DPIBypass.RandomMode randomMode = new(data, socket); - randomMode.Send(FragmentLength, FragmentDelay); + programMode.OnChunkDetailsReceived -= ProgramMode_OnChunkDetailsReceived; + programMode.OnChunkDetailsReceived += ProgramMode_OnChunkDetailsReceived; + programMode.DontChunkTheBiggestRequest = bp.DontChunkTheBiggestRequest; + programMode.SendInRandom = bp.SendInRandom; + programMode.Send(bp.FirstPartOfDataLength, bp.FragmentSize, bp.FragmentChunks, bp.FragmentDelay); } else socket.Send(data); } } - #endregion + private void ProgramMode_OnChunkDetailsReceived(object? sender, EventArgs e) + { + if (sender is string msg) + OnChunkDetailsReceived?.Invoke(msg, EventArgs.Empty); + } + + private void RandomMode_OnChunkDetailsReceived(object? sender, EventArgs e) + { + if (sender is string msg) + OnChunkDetailsReceived?.Invoke(msg, EventArgs.Empty); + } + } } diff --git a/SecureDNSClient/MsmhTools/Network.cs b/SecureDNSClient/MsmhTools/Network.cs index dd7b2c2..1509a3f 100644 --- a/SecureDNSClient/MsmhTools/Network.cs +++ b/SecureDNSClient/MsmhTools/Network.cs @@ -44,6 +44,56 @@ public static class Network return null; } + public static string UrlToHostAndPort(string url, int defaultPort, out int port) + { + url = url.Trim(); + + // Strip xxxx:// + if (url.Contains("//")) + { + string[] split = url.Split("//"); + if (!string.IsNullOrEmpty(split[1])) + url = split[1]; + } + + // Strip /xxxx (Path) + if (!url.Contains("//") && url.Contains('/')) + { + string[] split = url.Split('/'); + if (!string.IsNullOrEmpty(split[0])) + url = split[0]; + } + + string host = url; + port = defaultPort; + + // Split Host and Port + if (url.Contains("]:")) + { + // IPv6 domain + port + string[] split = url.Split("]:"); + if (split.Length == 2) + { + host = split[0] + "]"; + bool isInt = int.TryParse(split[1], out int result); + if (isInt) port = result; + } + } + else if (!url.Contains('[') && !url.Contains(']') && url.Contains(':')) + { + // Domain or IPv4 + string[] split = url.Split(':'); + if (split.Length == 2) + { + host = split[0]; + bool isInt = int.TryParse(split[1], out int result); + if (isInt) port = result; + } + } + + return host; + } + public static IPAddress? HostToIP(string host, bool getIPv6 = false) { IPAddress? result = null; @@ -579,6 +629,8 @@ public static void SetDNS(NetworkInterface nic, string dnsServers) Debug.WriteLine(ex.Message); } + Task.Delay(200).Wait(); + try { using ManagementClass managementClass = new("Win32_NetworkAdapterConfiguration"); @@ -602,6 +654,10 @@ public static void SetDNS(NetworkInterface nic, string dnsServers) } } + /// + /// Unset DNS to DHCP + /// + /// Network Interface public static void UnsetDNS(NetworkInterface nic) { // Requires Elevation - Can't Unset DNS when there is no Internet connectivity but netsh can :) @@ -644,6 +700,18 @@ public static void UnsetDNS(NetworkInterface nic) } } + /// + /// Unset DNS by seting DNS to Static + /// + /// Network Interface + /// Primary + /// Secondary + public static void UnsetDNS(NetworkInterface nic, string dns1, string dns2) + { + string dnsServers = $"{dns1},{dns2}"; + SetDNS(nic, dnsServers); + } + /// /// Check if DNS is set to Static or DHCP /// @@ -664,19 +732,23 @@ public static bool IsDnsSet(NetworkInterface nic, out string dnsServer1, out str for (int n = 0; n < lines.Count; n++) { string line = lines[n]; - if (n == 2 && line.Contains(':')) + // Get Primary + if (line.Contains(": ") && line.Contains('.') && line.Count(c => c == '.') == 3) { - string[] split1 = line.Split(':'); - if (split1.Length > 1) + string[] split = line.Split(": "); + if (split.Length > 1) { - dnsServer1 = split1[1].Trim(); + dnsServer1 = split[1].Trim(); + Debug.WriteLine($"DNS 1: {dnsServer1}"); } } - else if (n == 3) + + // Get Secondary + if (!line.Contains(": ") && line.Contains('.') && line.Count(c => c == '.') == 3) { dnsServer2 = line.Trim(); + Debug.WriteLine($"DNS 2: {dnsServer2}"); } - Debug.WriteLine(line); } //Debug.WriteLine(stdout); return !stdout.Contains("DHCP"); diff --git a/SecureDNSClient/Properties/PublishProfiles/FolderProfile.pubxml.user b/SecureDNSClient/Properties/PublishProfiles/FolderProfile.pubxml.user index 558984e..f0993aa 100644 --- a/SecureDNSClient/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/SecureDNSClient/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - True|2023-05-27T12:55:56.0498058Z;True|2023-05-27T14:50:19.0862471+04:30;True|2023-05-26T00:33:02.8133052+04:30;True|2023-05-26T00:22:55.5762345+04:30;True|2023-05-19T21:55:55.2053137+04:30;True|2023-05-04T21:14:13.1959990+04:30;True|2023-05-03T18:38:41.0925495+04:30;True|2023-05-03T18:22:56.1278337+04:30;True|2023-04-07T19:23:03.7575436+04:30;True|2023-04-07T19:01:53.8374192+04:30;True|2023-04-07T18:56:48.3465035+04:30;True|2023-02-23T19:42:36.6931238+03:30;True|2023-02-21T23:02:29.4417103+03:30;True|2023-02-21T22:58:29.4403662+03:30;True|2023-02-21T22:48:24.4128535+03:30;True|2023-02-21T22:27:17.9388815+03:30;True|2023-02-20T17:48:08.6532315+03:30;True|2023-02-16T01:42:22.8837631+03:30;True|2023-02-16T01:39:16.7954793+03:30;True|2023-02-15T21:24:18.8085514+03:30;True|2023-02-15T21:18:04.1969211+03:30;True|2023-02-15T21:15:01.3739223+03:30;True|2023-02-08T06:22:33.0414550+03:30;True|2023-02-08T05:20:18.9270105+03:30;True|2023-02-08T05:15:17.5374116+03:30;True|2023-02-08T05:03:44.0882459+03:30;True|2023-02-08T04:53:40.5516012+03:30;True|2023-02-08T02:23:19.0633758+03:30; + True|2023-05-30T13:28:01.2450123Z;True|2023-05-29T20:36:32.5291896+04:30;True|2023-05-29T20:18:12.2031439+04:30;True|2023-05-29T19:44:46.0704739+04:30;True|2023-05-27T17:25:56.0498058+04:30;True|2023-05-27T14:50:19.0862471+04:30;True|2023-05-26T00:33:02.8133052+04:30;True|2023-05-26T00:22:55.5762345+04:30;True|2023-05-19T21:55:55.2053137+04:30;True|2023-05-04T21:14:13.1959990+04:30;True|2023-05-03T18:38:41.0925495+04:30;True|2023-05-03T18:22:56.1278337+04:30;True|2023-04-07T19:23:03.7575436+04:30;True|2023-04-07T19:01:53.8374192+04:30;True|2023-04-07T18:56:48.3465035+04:30;True|2023-02-23T19:42:36.6931238+03:30;True|2023-02-21T23:02:29.4417103+03:30;True|2023-02-21T22:58:29.4403662+03:30;True|2023-02-21T22:48:24.4128535+03:30;True|2023-02-21T22:27:17.9388815+03:30;True|2023-02-20T17:48:08.6532315+03:30;True|2023-02-16T01:42:22.8837631+03:30;True|2023-02-16T01:39:16.7954793+03:30;True|2023-02-15T21:24:18.8085514+03:30;True|2023-02-15T21:18:04.1969211+03:30;True|2023-02-15T21:15:01.3739223+03:30;True|2023-02-08T06:22:33.0414550+03:30;True|2023-02-08T05:20:18.9270105+03:30;True|2023-02-08T05:15:17.5374116+03:30;True|2023-02-08T05:03:44.0882459+03:30;True|2023-02-08T04:53:40.5516012+03:30;True|2023-02-08T02:23:19.0633758+03:30; \ No newline at end of file diff --git a/SecureDNSClient/SecureDNS/SecureDNS.cs b/SecureDNSClient/SecureDNS/SecureDNS.cs index f1cccdf..3aedc43 100644 --- a/SecureDNSClient/SecureDNS/SecureDNS.cs +++ b/SecureDNSClient/SecureDNS/SecureDNS.cs @@ -246,17 +246,8 @@ public static async Task HostToCompanyOffline(string host) public static async Task UrlToCompanyOffline(string url) { - string host = "NotFound"; - Uri? uri = Network.UrlToUri(url); - - if (uri != null) - { - host = uri.Host; - if (!string.IsNullOrEmpty(host)) - return await HostToCompanyOffline(host); - } - - return host; + string host = Network.UrlToHostAndPort(url, 53, out int _); + return await HostToCompanyOffline(host); } public static async Task StampToCompanyOffline(string stampUrl) @@ -291,36 +282,32 @@ public static async Task StampToCompanyOffline(string stampUrl) public static async Task UrlToCompanyAsync(string url, string? proxyScheme = null) { string company = "Couldn't retrieve information."; - Uri? uri = Network.UrlToUri(url); - if (uri != null) + string? host = Network.UrlToHostAndPort(url, 443, out int _); + if (!string.IsNullOrWhiteSpace(host)) { - string? host = uri.Host; - if (!string.IsNullOrWhiteSpace(host)) + IPAddress? ipAddress = Network.HostToIP(host); + string? companyFull; + if (ipAddress != null) { - IPAddress? ipAddress = Network.HostToIP(host); - string? companyFull; - if (ipAddress != null) + if (proxyScheme == null) + companyFull = await Network.IpToCompanyAsync(ipAddress); + else + companyFull = await Network.IpToCompanyAsync(ipAddress, proxyScheme); + if (!string.IsNullOrWhiteSpace(companyFull)) { - if (proxyScheme == null) - companyFull = await Network.IpToCompanyAsync(ipAddress); - else - companyFull = await Network.IpToCompanyAsync(ipAddress, proxyScheme); - if (!string.IsNullOrWhiteSpace(companyFull)) + company = string.Empty; + string[] split = companyFull.Split(" "); + for (int n = 0; n < split.Length; n++) { - company = string.Empty; - string[] split = companyFull.Split(" "); - for (int n = 0; n < split.Length; n++) - { - string s = split[n]; - if (n != 0) - company += s + " "; - } - company = company.Trim(); + string s = split[n]; + if (n != 0) + company += s + " "; } + company = company.Trim(); } } } - + return company; } @@ -376,13 +363,10 @@ public static async Task HostToCompanyAsync(string hostsFilePath) string company = await UrlToCompanyAsync(dns); if (!company.Contains("Couldn't retrieve information.")) { - Uri? uri = Network.UrlToUri(dns); - if (uri != null) - { - object hostToCom = uri.Host + "|" + company; - HostToCompanyList.Add(hostToCom); - Debug.WriteLine(hostToCom); - } + string host = Network.UrlToHostAndPort(dns, 443, out int _); + object hostToCom = host + "|" + company; + HostToCompanyList.Add(hostToCom); + Debug.WriteLine(hostToCom); } } // Remove Duplicates diff --git a/SecureDNSClient/SecureDNSClient.csproj b/SecureDNSClient/SecureDNSClient.csproj index c414f16..0769b97 100644 --- a/SecureDNSClient/SecureDNSClient.csproj +++ b/SecureDNSClient/SecureDNSClient.csproj @@ -9,7 +9,7 @@ app.manifest MSasanMH SDC - Secure DNS Client - $(VersionPrefix)2.1.2 + $(VersionPrefix)2.1.3 SecureDNSClient.png SecureDNSClientMulti.ico diff --git a/SecureDNSClientPortable/Properties/PublishProfiles/FolderProfile.pubxml.user b/SecureDNSClientPortable/Properties/PublishProfiles/FolderProfile.pubxml.user index 9f3f446..5e4446a 100644 --- a/SecureDNSClientPortable/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/SecureDNSClientPortable/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - True|2023-05-27T12:55:27.9631407Z;True|2023-05-27T14:50:40.9938592+04:30;True|2023-05-26T00:22:04.4226759+04:30;True|2023-05-19T21:55:03.6988953+04:30;True|2023-05-04T21:13:44.0531282+04:30;True|2023-05-03T18:20:58.6158351+04:30;True|2023-04-07T19:22:18.1443242+04:30;True|2023-04-07T19:01:23.1687551+04:30;True|2023-04-07T18:56:25.8534493+04:30;True|2023-02-23T19:42:03.7111255+03:30;True|2023-02-21T22:26:35.4429594+03:30;True|2023-02-20T17:47:25.0792312+03:30;True|2023-02-16T01:42:37.6467629+03:30;True|2023-02-15T22:16:38.0474815+03:30;True|2023-02-15T21:50:25.4952184+03:30;True|2023-02-15T21:49:01.8562159+03:30; + True|2023-05-30T13:27:19.0001069Z;True|2023-05-29T20:17:44.2223328+04:30;True|2023-05-29T19:43:15.8911213+04:30;True|2023-05-27T17:25:27.9631407+04:30;True|2023-05-27T14:50:40.9938592+04:30;True|2023-05-26T00:22:04.4226759+04:30;True|2023-05-19T21:55:03.6988953+04:30;True|2023-05-04T21:13:44.0531282+04:30;True|2023-05-03T18:20:58.6158351+04:30;True|2023-04-07T19:22:18.1443242+04:30;True|2023-04-07T19:01:23.1687551+04:30;True|2023-04-07T18:56:25.8534493+04:30;True|2023-02-23T19:42:03.7111255+03:30;True|2023-02-21T22:26:35.4429594+03:30;True|2023-02-20T17:47:25.0792312+03:30;True|2023-02-16T01:42:37.6467629+03:30;True|2023-02-15T22:16:38.0474815+03:30;True|2023-02-15T21:50:25.4952184+03:30;True|2023-02-15T21:49:01.8562159+03:30; \ No newline at end of file diff --git a/SecureDNSClientPortable/SecureDNSClientPortable.csproj b/SecureDNSClientPortable/SecureDNSClientPortable.csproj index a9a7b8e..5a4b2f8 100644 --- a/SecureDNSClientPortable/SecureDNSClientPortable.csproj +++ b/SecureDNSClientPortable/SecureDNSClientPortable.csproj @@ -7,7 +7,7 @@ true enable SecureDNSClientMulti.ico - $(VersionPrefix)2.1.2 + $(VersionPrefix)2.1.3 MSasanMH app.manifest