From c795fd71f5ee9b985ebabb10d16720cfa53c0e31 Mon Sep 17 00:00:00 2001 From: EonaCat Date: Mon, 13 Feb 2023 19:08:20 +0100 Subject: [PATCH] Updated --- EonaCat.DnsTester/MainForm.Designer.cs | 34 ++++++++++++- EonaCat.DnsTester/MainForm.cs | 69 ++++++++++++++++++-------- 2 files changed, 81 insertions(+), 22 deletions(-) diff --git a/EonaCat.DnsTester/MainForm.Designer.cs b/EonaCat.DnsTester/MainForm.Designer.cs index e74ffc2..58189e1 100644 --- a/EonaCat.DnsTester/MainForm.Designer.cs +++ b/EonaCat.DnsTester/MainForm.Designer.cs @@ -47,6 +47,8 @@ this.CustomDns2 = new System.Windows.Forms.TextBox(); this.lslStatus = new System.Windows.Forms.Label(); this.StatusBox = new System.Windows.Forms.ListBox(); + this.chkDns1 = new System.Windows.Forms.CheckBox(); + this.chkDns2 = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // ResultView @@ -224,13 +226,39 @@ this.StatusBox.Size = new System.Drawing.Size(2209, 376); this.StatusBox.TabIndex = 23; // - // TesterUI + // chkDns1 + // + this.chkDns1.AutoSize = true; + this.chkDns1.Checked = true; + this.chkDns1.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkDns1.Location = new System.Drawing.Point(277, 205); + this.chkDns1.Name = "chkDns1"; + this.chkDns1.Size = new System.Drawing.Size(245, 36); + this.chkDns1.TabIndex = 24; + this.chkDns1.Text = "Test dns server"; + this.chkDns1.UseVisualStyleBackColor = true; + // + // chkDns2 + // + this.chkDns2.AutoSize = true; + this.chkDns2.Checked = true; + this.chkDns2.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkDns2.Location = new System.Drawing.Point(1229, 205); + this.chkDns2.Name = "chkDns2"; + this.chkDns2.Size = new System.Drawing.Size(245, 36); + this.chkDns2.TabIndex = 25; + this.chkDns2.Text = "Test dns server"; + this.chkDns2.UseVisualStyleBackColor = true; + // + // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(240F, 240F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoSize = true; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.ClientSize = new System.Drawing.Size(2517, 1693); + this.Controls.Add(this.chkDns2); + this.Controls.Add(this.chkDns1); this.Controls.Add(this.StatusBox); this.Controls.Add(this.lslStatus); this.Controls.Add(this.CustomDns2); @@ -247,7 +275,7 @@ this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7); this.MaximizeBox = false; - this.Name = "TesterUI"; + this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "EonaCat.DnsTester"; this.Load += new System.EventHandler(this.TesterUI_Load); @@ -276,6 +304,8 @@ private System.Windows.Forms.TextBox CustomDns2; private System.Windows.Forms.Label lslStatus; private System.Windows.Forms.ListBox StatusBox; + private System.Windows.Forms.CheckBox chkDns1; + private System.Windows.Forms.CheckBox chkDns2; } } diff --git a/EonaCat.DnsTester/MainForm.cs b/EonaCat.DnsTester/MainForm.cs index 8e0c746..6272758 100644 --- a/EonaCat.DnsTester/MainForm.cs +++ b/EonaCat.DnsTester/MainForm.cs @@ -6,6 +6,7 @@ using System.Net.Sockets; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Windows.Forms; namespace EonaCat.DnsTester @@ -15,6 +16,8 @@ namespace EonaCat.DnsTester private bool UseCustomDnsServers = false; public string DNS1, DNS2; + public bool IsRunning { get; private set; } + public MainForm() { InitializeComponent(); @@ -28,13 +31,27 @@ namespace EonaCat.DnsTester if (this.UseCustomDnsServers) { - DNS1 = CustomDns1.Text; - DNS2 = CustomDns2.Text; + if (chkDns1.Checked) + { + DNS1 = CustomDns1.Text; + } + + if (chkDns2.Checked) + { + DNS2 = CustomDns2.Text; + } } else { - DNS1 = DnsList1.SelectedValue.ToString(); - DNS2 = DnsList2.SelectedValue.ToString(); + if (chkDns1.Checked) + { + DNS1 = DnsList1.SelectedValue.ToString(); + } + + if (chkDns2.Checked) + { + DNS2 = DnsList2.SelectedValue.ToString(); + } } @@ -62,7 +79,17 @@ namespace EonaCat.DnsTester ResultView.Update(); Application.DoEvents(); - CheckDNS(CleanNames, CleanNamesCount, DNS1, DNS2); + if (IsRunning) + { + return; + } + + Task.Run(() => + { + IsRunning = true; + CheckDNS(CleanNames, CleanNamesCount, DNS1, DNS2); + IsRunning = false; + }); } @@ -233,13 +260,13 @@ namespace EonaCat.DnsTester DNSsocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, DNSReceiveTimeout); IPEndPoint dnsEP1 = null; - if (!string.IsNullOrWhiteSpace(DNSAddress1)) + if (chkDns1.Checked && !string.IsNullOrWhiteSpace(DNSAddress1)) { dnsEP1 = new IPEndPoint(IPAddress.Parse(DNSAddress1), IPPort); } IPEndPoint dnsEP2 = null; - if (!string.IsNullOrWhiteSpace(DNSAddress2)) + if (chkDns2.Checked && !string.IsNullOrWhiteSpace(DNSAddress2)) { dnsEP2 = new IPEndPoint(IPAddress.Parse(DNSAddress2), IPPort); } @@ -247,25 +274,29 @@ namespace EonaCat.DnsTester // Start the clock StartTime = DateTime.Now.Ticks; - // i=0; // for testing - do one for (i = 0; i < URLNamescount; i++) { URLNameStart = URLNames[i].Substring(0, URLNames[i].IndexOf(".")); DomainName = URLNames[i].Substring(URLNames[i].IndexOf(".") + 1, URLNames[i].Length - URLNames[i].IndexOf(".") - 1); - // Build the query - QueryString = TransactionID1 + TypeString + (char)URLNameStart.Length + URLNameStart + (char)DomainName.Length + DomainName + TrailerString; - Sendbytes = Encoding.ASCII.GetBytes(QueryString); - if (dnsEP1 != null) + + if (chkDns1.Checked) { - DNSsocket.SendTo(Sendbytes, Sendbytes.Length, SocketFlags.None, dnsEP1); + QueryString = TransactionID1 + TypeString + (char)URLNameStart.Length + URLNameStart + (char)DomainName.Length + DomainName + TrailerString; + Sendbytes = Encoding.ASCII.GetBytes(QueryString); + if (dnsEP1 != null) + { + DNSsocket.SendTo(Sendbytes, Sendbytes.Length, SocketFlags.None, dnsEP1); + } } - // send the same message to both DNS servers except for the transaction ID - QueryString = TransactionID2 + TypeString + (char)URLNameStart.Length + URLNameStart + (char)DomainName.Length + DomainName + TrailerString; - Sendbytes = Encoding.ASCII.GetBytes(QueryString); - if (dnsEP2 != null) + if (chkDns2.Checked) { - DNSsocket.SendTo(Sendbytes, Sendbytes.Length, SocketFlags.None, dnsEP2); + QueryString = TransactionID2 + TypeString + (char)URLNameStart.Length + URLNameStart + (char)DomainName.Length + DomainName + TrailerString; + Sendbytes = Encoding.ASCII.GetBytes(QueryString); + if (dnsEP2 != null) + { + DNSsocket.SendTo(Sendbytes, Sendbytes.Length, SocketFlags.None, dnsEP2); + } } } @@ -275,8 +306,6 @@ namespace EonaCat.DnsTester { // wait for a response up to timeout more: DNSsocket.Receive(Receivebytes); - - // make sure the message returned is ours if (Receivebytes[0] == Sendbytes[0] && (Receivebytes[1] == 0x31) || (Receivebytes[1] == 0x32)) {