diff --git a/EonaCat.DnsTester/EonaCat.DnsTester.csproj b/EonaCat.DnsTester/EonaCat.DnsTester.csproj index 10634cc..6528d28 100644 --- a/EonaCat.DnsTester/EonaCat.DnsTester.csproj +++ b/EonaCat.DnsTester/EonaCat.DnsTester.csproj @@ -2,7 +2,7 @@ WinExe - net6.0-windows + net7.0-windows true false @@ -28,5 +28,8 @@ SettingsSingleFileGenerator Settings.Designer.cs + + PreserveNewest + \ No newline at end of file diff --git a/EonaCat.DnsTester/Helpers/DnsHelper.cs b/EonaCat.DnsTester/Helpers/DnsHelper.cs index c4c823e..0148186 100644 --- a/EonaCat.DnsTester/Helpers/DnsHelper.cs +++ b/EonaCat.DnsTester/Helpers/DnsHelper.cs @@ -21,6 +21,7 @@ namespace EonaCat.DnsTester.Helpers { client.DontFragment = true; client.EnableBroadcast = false; + client.Client.SendTimeout = DnsSendTimeout; client.Client.ReceiveTimeout = DnsReceiveTimeout; byte[] responseBytes = null; if (FakeResponse) @@ -42,6 +43,7 @@ namespace EonaCat.DnsTester.Helpers // For testing purposes public static bool FakeResponse { get; set; } + public static int DnsSendTimeout { get; set; } = 5; public static int DnsReceiveTimeout { get; set; } = 5; diff --git a/EonaCat.DnsTester/Helpers/UrlHelper.cs b/EonaCat.DnsTester/Helpers/UrlHelper.cs index 8f10fbb..e930917 100644 --- a/EonaCat.DnsTester/Helpers/UrlHelper.cs +++ b/EonaCat.DnsTester/Helpers/UrlHelper.cs @@ -39,52 +39,55 @@ namespace EonaCat.DnsTester.Helpers string url = searchEngine.Value + letters; - try + using (var client = new WebClient()) { - using (var client = new WebClient()) + string responseString = null; + try { - string responseString = client.DownloadString(url); + responseString = client.DownloadString(url); + } + catch (Exception ex) + { + searchEngineUrls.Remove(searchEngine.Key); + SetStatus($"{searchEngine.Key}: {ex.Message}"); + } - // find all .xxx.com addresses - MatchCollection hostNames = Regex.Matches(responseString, @"[.](\w+[.]com)"); + if (responseString == null) + { + continue; + } - // Loop through the match collection to retrieve all matches and delete the leading "." - HashSet uniqueNames = new HashSet(); - foreach (Match match in hostNames) + // find all .xxx.com addresses + MatchCollection hostNames = Regex.Matches(responseString, @"[.](\w+[.]com)"); + + // Loop through the match collection to retrieve all matches and delete the leading "." + HashSet uniqueNames = new HashSet(); + foreach (Match match in hostNames) + { + string name = match.Groups[1].Value; + if (name != $"{searchEngine.Key.ToLower()}.com") { - string name = match.Groups[1].Value; - if (name != $"{searchEngine.Key.ToLower()}.com") - { - uniqueNames.Add(name); - } - } - - // Add the names to the list - foreach (string name in uniqueNames) - { - if (urls.Count >= totalUrls) - { - break; - } - - if (!urls.Contains(name)) - { - urls.Add(name); - } + uniqueNames.Add(name); } } - await Task.Delay(100); - } - catch (Exception ex) - { - searchEngineUrls.Remove(searchEngine.Key); - SetStatus($"{searchEngine.Key}: {ex.Message}"); - } - finally - { - letters = GetRandomLetters(); + // Add the names to the list + foreach (string name in uniqueNames) + { + if (urls.Count >= totalUrls) + { + break; + } + + if (!urls.Contains(name)) + { + urls.Add(name); + } + } } + + letters = GetRandomLetters(); + await Task.Delay(100); } var urlText = "url" + (urls.Count > 1 ? "'s" : string.Empty); diff --git a/EonaCat.DnsTester/MainForm.cs b/EonaCat.DnsTester/MainForm.cs index 6cf9732..f00329d 100644 --- a/EonaCat.DnsTester/MainForm.cs +++ b/EonaCat.DnsTester/MainForm.cs @@ -55,12 +55,6 @@ namespace EonaCat.DnsTester urls = await UrlHelper.RetrieveUrls(numThreads, numUrlsPerThread); AddUrlToView(urls); - - if (IsRunning) - { - return; - } - IsRunning = true; await Process(_recordType, urls.ToArray(), _dnsServer1, _dnsServer2); IsRunning = false; @@ -199,14 +193,10 @@ namespace EonaCat.DnsTester for (int i = 0; i < urlsTotal; i++) { - await Task.Run(async () => - { - var currentUrl = urls[i]; - - await ExecuteDns1(recordType, dnsAddress1, currentUrl, dnsId1, i); - if (!chkDns2.Checked) return; - await ExecuteDns2(recordType, dnsAddress2, currentUrl, dnsId2, i); - }); + var currentUrl = urls[i]; + await ExecuteDns1(recordType, dnsAddress1, currentUrl, dnsId1, i); + if (!chkDns2.Checked) return; + await ExecuteDns2(recordType, dnsAddress2, currentUrl, dnsId2, i); await Task.Delay(100); } } diff --git a/Screenshots/1.png b/Screenshots/1.png new file mode 100644 index 0000000..f52c087 Binary files /dev/null and b/Screenshots/1.png differ