Updated
This commit is contained in:
parent
4afe9153ed
commit
d3aef63feb
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EonaCat.DnsTester.Helpers
|
||||
{
|
||||
|
@ -12,7 +13,7 @@ namespace EonaCat.DnsTester.Helpers
|
|||
private static readonly RandomNumberGenerator _randomNumberGenerator = RandomNumberGenerator.Create();
|
||||
public static event EventHandler<string> Log;
|
||||
|
||||
public static void GetRandomUrls(ref List<string> urlList, int totalUrls)
|
||||
private static async Task<List<string>> GetRandomUrls(int totalUrls)
|
||||
{
|
||||
var letters = GetRandomLetters();
|
||||
|
||||
|
@ -30,8 +31,7 @@ namespace EonaCat.DnsTester.Helpers
|
|||
|
||||
Random rand = new Random();
|
||||
|
||||
List<string> urls = urlList;
|
||||
|
||||
List<string> urls = new List<string>();
|
||||
while (urls.Count < totalUrls)
|
||||
{
|
||||
int index = rand.Next(searchEngineUrls.Count);
|
||||
|
@ -73,6 +73,8 @@ namespace EonaCat.DnsTester.Helpers
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(100);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -85,9 +87,27 @@ namespace EonaCat.DnsTester.Helpers
|
|||
}
|
||||
}
|
||||
|
||||
urlList = urls;
|
||||
var urlText = "url" + (urlList.Count > 1 ? "'s" : string.Empty);
|
||||
SetStatus($"{urlList.Count} random {urlText} found");
|
||||
var urlText = "url" + (urls.Count > 1 ? "'s" : string.Empty);
|
||||
SetStatus($"{urls.Count} random {urlText} found");
|
||||
return urls;
|
||||
}
|
||||
|
||||
public static async Task<List<string>> RetrieveUrls(int numThreads, int numUrlsPerThread)
|
||||
{
|
||||
Task[] tasks = new Task[numThreads];
|
||||
|
||||
List<string> urlList = new List<string>();
|
||||
|
||||
// start each thread to retrieve a subset of unique URLs
|
||||
for (int i = 0; i < numThreads; i++)
|
||||
{
|
||||
tasks[i] = Task.Run(async () => urlList.AddRange(await GetRandomUrls(numUrlsPerThread)));
|
||||
}
|
||||
|
||||
// wait for all threads to complete
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
return urlList;
|
||||
}
|
||||
|
||||
private static string GetRandomLetters()
|
||||
|
|
|
@ -60,10 +60,13 @@
|
|||
txtResolveIP = new System.Windows.Forms.TextBox();
|
||||
label5 = new System.Windows.Forms.Label();
|
||||
label1 = new System.Windows.Forms.Label();
|
||||
label2 = new System.Windows.Forms.Label();
|
||||
numericUpDown2 = new System.Windows.Forms.NumericUpDown();
|
||||
panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit();
|
||||
panel2.SuspendLayout();
|
||||
panel3.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// RunTest
|
||||
|
@ -81,6 +84,8 @@
|
|||
// panel1
|
||||
//
|
||||
panel1.BackColor = System.Drawing.SystemColors.ControlLight;
|
||||
panel1.Controls.Add(numericUpDown2);
|
||||
panel1.Controls.Add(label2);
|
||||
panel1.Controls.Add(comboBox1);
|
||||
panel1.Controls.Add(numericUpDown1);
|
||||
panel1.Controls.Add(label3);
|
||||
|
@ -380,6 +385,25 @@
|
|||
label1.TabIndex = 66;
|
||||
label1.Text = "Resolve ip address:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new System.Drawing.Point(566, 228);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new System.Drawing.Size(201, 41);
|
||||
label2.TabIndex = 60;
|
||||
label2.Text = "Total Threads:";
|
||||
//
|
||||
// numericUpDown2
|
||||
//
|
||||
numericUpDown2.Location = new System.Drawing.Point(804, 228);
|
||||
numericUpDown2.Maximum = new decimal(new int[] { 1000000000, 0, 0, 0 });
|
||||
numericUpDown2.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
|
||||
numericUpDown2.Name = "numericUpDown2";
|
||||
numericUpDown2.Size = new System.Drawing.Size(120, 47);
|
||||
numericUpDown2.TabIndex = 61;
|
||||
numericUpDown2.Value = new decimal(new int[] { 5, 0, 0, 0 });
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(240F, 240F);
|
||||
|
@ -404,6 +428,7 @@
|
|||
panel2.ResumeLayout(false);
|
||||
panel3.ResumeLayout(false);
|
||||
panel3.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
|
@ -439,6 +464,8 @@
|
|||
private System.Windows.Forms.TextBox txtResolveIP;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.NumericUpDown numericUpDown2;
|
||||
private System.Windows.Forms.Label label2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,10 +46,13 @@ namespace EonaCat.DnsTester
|
|||
List<string> urls = new List<string>();
|
||||
SetupView();
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
UrlHelper.GetRandomUrls(ref urls, (int)numericUpDown1.Value);
|
||||
});
|
||||
|
||||
int numThreads = (int)numericUpDown2.Value; // number of concurrent threads to use
|
||||
int maxUrls = (int)numericUpDown1.Value; // maximum number of unique URLs to retrieve
|
||||
int numUrlsPerThread = maxUrls / numThreads;
|
||||
|
||||
|
||||
urls = await UrlHelper.RetrieveUrls(numThreads, numUrlsPerThread);
|
||||
AddUrlToView(urls);
|
||||
|
||||
|
||||
|
@ -196,12 +199,14 @@ namespace EonaCat.DnsTester
|
|||
|
||||
for (int i = 0; i < urlsTotal; i++)
|
||||
{
|
||||
var currentUrl = urls[i];
|
||||
|
||||
await ExecuteDns1(recordType, dnsAddress1, currentUrl, dnsId1, i);
|
||||
if (!chkDns2.Checked) continue;
|
||||
await ExecuteDns2(recordType, dnsAddress2, currentUrl, dnsId2, 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);
|
||||
});
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
|
@ -279,45 +284,47 @@ namespace EonaCat.DnsTester
|
|||
$"ResourceRecord: Name: {answer.Name} : Type : {answer.Type} : Data : {answer.Data}");
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < ResultView.Items.Count; i++)
|
||||
ResultView.Invoke(() =>
|
||||
{
|
||||
foreach (var answer in dnsResponse.Answers)
|
||||
for (int i = 0; i < ResultView.Items.Count; i++)
|
||||
{
|
||||
if (ResultView.Items[i].Text != $"{answer.Name.TrimEnd('.')}")
|
||||
continue;
|
||||
|
||||
string sDeltaTime;
|
||||
switch (dnsResponse.DnsId)
|
||||
foreach (var answer in dnsResponse.Answers)
|
||||
{
|
||||
case "Dns1":
|
||||
ResultView.Items[i].SubItems[1].Text =
|
||||
Convert.ToString(answer.Data);
|
||||
sDeltaTime = Convert.ToString(deltaTime);
|
||||
ResultView.Items[i].SubItems[2].Text =
|
||||
sDeltaTime.Length > 5 ? sDeltaTime.Substring(0, 5) : sDeltaTime;
|
||||
ResultView.Items[i].ForeColor = System.Drawing.Color.Red;
|
||||
ResultView.EnsureVisible(i);
|
||||
ResultView.Update();
|
||||
Application.DoEvents();
|
||||
ResultView.Items[i].ForeColor = System.Drawing.Color.Black;
|
||||
break;
|
||||
if (ResultView.Items[i].Text != $"{answer.Name.TrimEnd('.')}")
|
||||
continue;
|
||||
|
||||
case "Dns2":
|
||||
ResultView.Items[i].SubItems[3].Text =
|
||||
Convert.ToString(answer.Data);
|
||||
sDeltaTime = Convert.ToString(deltaTime);
|
||||
ResultView.Items[i].SubItems[4].Text =
|
||||
sDeltaTime.Length > 5 ? sDeltaTime.Substring(0, 5) : sDeltaTime;
|
||||
ResultView.Items[i].ForeColor = System.Drawing.Color.Red;
|
||||
ResultView.EnsureVisible(i);
|
||||
ResultView.Update();
|
||||
Application.DoEvents();
|
||||
ResultView.Items[i].ForeColor = System.Drawing.Color.Black;
|
||||
break;
|
||||
string sDeltaTime;
|
||||
switch (dnsResponse.DnsId)
|
||||
{
|
||||
case "Dns1":
|
||||
ResultView.Items[i].SubItems[1].Text =
|
||||
Convert.ToString(answer.Data);
|
||||
sDeltaTime = Convert.ToString(deltaTime);
|
||||
ResultView.Items[i].SubItems[2].Text =
|
||||
sDeltaTime.Length > 5 ? sDeltaTime.Substring(0, 5) : sDeltaTime;
|
||||
ResultView.Items[i].ForeColor = System.Drawing.Color.Red;
|
||||
ResultView.EnsureVisible(i);
|
||||
ResultView.Update();
|
||||
Application.DoEvents();
|
||||
ResultView.Items[i].ForeColor = System.Drawing.Color.Black;
|
||||
break;
|
||||
|
||||
case "Dns2":
|
||||
ResultView.Items[i].SubItems[3].Text =
|
||||
Convert.ToString(answer.Data);
|
||||
sDeltaTime = Convert.ToString(deltaTime);
|
||||
ResultView.Items[i].SubItems[4].Text =
|
||||
sDeltaTime.Length > 5 ? sDeltaTime.Substring(0, 5) : sDeltaTime;
|
||||
ResultView.Items[i].ForeColor = System.Drawing.Color.Red;
|
||||
ResultView.EnsureVisible(i);
|
||||
ResultView.Update();
|
||||
Application.DoEvents();
|
||||
ResultView.Items[i].ForeColor = System.Drawing.Color.Black;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async void btnResolveIP_Click(object sender, EventArgs e)
|
||||
|
|
Loading…
Reference in New Issue