Compare commits

..

9 Commits

Author SHA1 Message Date
e552bf1925 Speedup URL retrieval 2023-07-19 17:15:22 +02:00
6ae0e0b779 Updated UI 2023-07-19 16:35:30 +02:00
16c642dd20 Updated 2023-07-17 12:53:25 +02:00
41a3f72560 Updated 2023-03-03 10:44:13 +01:00
454beb78a8 Updated 2023-03-03 10:40:01 +01:00
80f09ecf39 Updated 2023-03-02 19:33:00 +01:00
46f8786acd Updated 2023-03-02 19:20:08 +01:00
72ecce97a9 Updated 2023-03-02 19:06:28 +01:00
36aaddf85e Updated 2023-03-02 16:21:19 +01:00
9 changed files with 628 additions and 320 deletions

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -11,7 +10,7 @@ namespace EonaCat.DnsTester.Helpers
class DnsHelper
{
public static event EventHandler<string> OnLog;
public static async Task<DnsResponse> SendDnsQueryPacket(string dnsId, string server, int port, byte[] queryBytes)
public static async Task<DnsResponse> SendDnsQueryPacketAsync(string dnsId, string server, int port, byte[] queryBytes)
{
// Start the clock
var startTime = DateTime.Now.Ticks;
@@ -30,12 +29,12 @@ namespace EonaCat.DnsTester.Helpers
}
else
{
await client.SendAsync(queryBytes, queryBytes.Length, endPoint);
var responseResult = await client.ReceiveAsync();
await client.SendAsync(queryBytes, queryBytes.Length, endPoint).ConfigureAwait(false);
var responseResult = await client.ReceiveAsync().ConfigureAwait(false);
responseBytes = responseResult.Buffer;
}
DnsResponse response = ParseDnsResponsePacket(dnsId, startTime, server, responseBytes);
var response = ParseDnsResponsePacket(dnsId, startTime, server, responseBytes);
return response;
}
}
@@ -49,16 +48,16 @@ namespace EonaCat.DnsTester.Helpers
public static byte[] CreateDnsQueryPacket(string domainName, DnsRecordType recordType)
{
Random random = new Random();
var random = new Random();
// DNS header
ushort id = (ushort)random.Next(0, 65536);
ushort flags = (ushort)0x0100; // recursion desired
var id = (ushort)random.Next(0, 65536);
var flags = (ushort)0x0100; // recursion desired
ushort qdcount = 1;
ushort ancount = 0;
ushort nscount = 0;
ushort arcount = 0;
byte[] headerBytes = new byte[]
var headerBytes = new byte[]
{
(byte)(id >> 8), (byte)(id & 0xff),
(byte)(flags >> 8), (byte)(flags & 0xff),
@@ -69,28 +68,28 @@ namespace EonaCat.DnsTester.Helpers
};
// DNS question
string[] labels = domainName.Split('.');
byte[] qnameBytes = new byte[domainName.Length + 2];
int qnameIndex = 0;
foreach (string label in labels)
var labels = domainName.Split('.');
var qnameBytes = new byte[domainName.Length + 2];
var qnameIndex = 0;
foreach (var label in labels)
{
qnameBytes[qnameIndex++] = (byte)label.Length;
foreach (char c in label)
foreach (var c in label)
{
qnameBytes[qnameIndex++] = (byte)c;
}
}
qnameBytes[qnameIndex++] = 0;
byte[] qtypeBytes = new byte[] { (byte)((ushort)recordType >> 8), (byte)((ushort)recordType & 0xff) };
byte[] qclassBytes = new byte[] { 0, 1 }; // internet class
byte[] questionBytes = new byte[qnameBytes.Length + qtypeBytes.Length + qclassBytes.Length];
var qtypeBytes = new byte[] { (byte)((ushort)recordType >> 8), (byte)((ushort)recordType & 0xff) };
var qclassBytes = new byte[] { 0, 1 }; // internet class
var questionBytes = new byte[qnameBytes.Length + qtypeBytes.Length + qclassBytes.Length];
qnameBytes.CopyTo(questionBytes, 0);
qtypeBytes.CopyTo(questionBytes, qnameBytes.Length);
qclassBytes.CopyTo(questionBytes, qnameBytes.Length + qtypeBytes.Length);
// Combine the header and question to form the DNS query packet
byte[] queryBytes = new byte[headerBytes.Length + questionBytes.Length];
var queryBytes = new byte[headerBytes.Length + questionBytes.Length];
headerBytes.CopyTo(queryBytes, 0);
questionBytes.CopyTo(queryBytes, headerBytes.Length);
@@ -100,15 +99,15 @@ namespace EonaCat.DnsTester.Helpers
static DnsQuestion ParseDnsQuestionRecord(byte[] queryBytes, ref int offset)
{
// Parse the DNS name
string name = DnsNameParser.ParseName(queryBytes, ref offset);
var name = DnsNameParser.ParseName(queryBytes, ref offset);
if (name == null)
{
return null;
}
// Parse the DNS type and class
ushort type = (ushort)((queryBytes[offset] << 8) | queryBytes[offset + 1]);
ushort qclass = (ushort)((queryBytes[offset + 2] << 8) | queryBytes[offset + 3]);
var type = (ushort)((queryBytes[offset] << 8) | queryBytes[offset + 1]);
var qclass = (ushort)((queryBytes[offset + 2] << 8) | queryBytes[offset + 3]);
offset += 4;
return new DnsQuestion
@@ -158,28 +157,28 @@ namespace EonaCat.DnsTester.Helpers
var offset = 0;
// Parse the DNS header
ushort id = (ushort)((responseBytes[0] << 8) | responseBytes[1]);
ushort flags = (ushort)((responseBytes[2] << 8) | responseBytes[3]);
bool isResponse = (flags & 0x8000) != 0;
ushort qdcount = (ushort)((responseBytes[4] << 8) | responseBytes[5]);
ushort ancount = (ushort)((responseBytes[6] << 8) | responseBytes[7]);
var id = (ushort)((responseBytes[0] << 8) | responseBytes[1]);
var flags = (ushort)((responseBytes[2] << 8) | responseBytes[3]);
var isResponse = (flags & 0x8000) != 0;
var qdcount = (ushort)((responseBytes[4] << 8) | responseBytes[5]);
var ancount = (ushort)((responseBytes[6] << 8) | responseBytes[7]);
if (!isResponse)
{
throw new Exception("Invalid DNS response");
}
ushort nscount = (ushort)((responseBytes[8] << 8) | responseBytes[9]);
ushort arcount = (ushort)((responseBytes[10] << 8) | responseBytes[11]);
var nscount = (ushort)((responseBytes[8] << 8) | responseBytes[9]);
var arcount = (ushort)((responseBytes[10] << 8) | responseBytes[11]);
// We parsed the header set the offset past the header
offset = 12;
List<DnsQuestion> questions = new List<DnsQuestion>();
var questions = new List<DnsQuestion>();
for (int i = 0; i < qdcount; i++)
for (var i = 0; i < qdcount; i++)
{
DnsQuestion question = ParseDnsQuestionRecord(responseBytes, ref offset);
var question = ParseDnsQuestionRecord(responseBytes, ref offset);
if (question != null)
{
questions.Add(question);
@@ -187,12 +186,12 @@ namespace EonaCat.DnsTester.Helpers
}
// Parse the DNS answer records
List<ResourceRecord> answers = new List<ResourceRecord>();
for (int i = 0; i < ancount; i++)
var answers = new List<ResourceRecord>();
for (var i = 0; i < ancount; i++)
{
try
{
ResourceRecord answer = ParseDnsAnswerRecord(responseBytes, ref offset);
var answer = ParseDnsAnswerRecord(responseBytes, ref offset);
if (answer != null)
{
answers.Add(answer);
@@ -205,12 +204,12 @@ namespace EonaCat.DnsTester.Helpers
}
// Parse the DNS authority records
List<ResourceRecord> authorities = new List<ResourceRecord>();
for (int i = 0; i < nscount; i++)
var authorities = new List<ResourceRecord>();
for (var i = 0; i < nscount; i++)
{
try
{
ResourceRecord authority = ParseDnsAnswerRecord(responseBytes, ref offset);
var authority = ParseDnsAnswerRecord(responseBytes, ref offset);
if (authority != null)
{
authorities.Add(authority);
@@ -223,12 +222,12 @@ namespace EonaCat.DnsTester.Helpers
}
// Parse the DNS additional records
List<ResourceRecord> additionals = new List<ResourceRecord>();
for (int i = 0; i < arcount; i++)
var additionals = new List<ResourceRecord>();
for (var i = 0; i < arcount; i++)
{
try
{
ResourceRecord additional = ParseDnsAnswerRecord(responseBytes, ref offset);
var additional = ParseDnsAnswerRecord(responseBytes, ref offset);
if (additional != null)
{
additionals.Add(additional);
@@ -258,23 +257,23 @@ namespace EonaCat.DnsTester.Helpers
static ResourceRecord ParseDnsAnswerRecord(byte[] responseBytes, ref int offset)
{
// Parse the DNS name
string name = DnsNameParser.ExtractDomainName(responseBytes, ref offset);
var name = DnsNameParser.ExtractDomainName(responseBytes, ref offset);
if (name == null)
{
return null;
}
// Parse the DNS type, class, ttl, and data length
DnsRecordType type = (DnsRecordType)((responseBytes[offset++] << 8) + responseBytes[offset++]);
DnsRecordClass klass = (DnsRecordClass)((responseBytes[offset++] << 8) + responseBytes[offset++]);
int ttl = (responseBytes[offset++] << 24) + (responseBytes[offset++] << 16) + (responseBytes[offset++] << 8) + responseBytes[offset++];
var type = (DnsRecordType)((responseBytes[offset++] << 8) + responseBytes[offset++]);
var klass = (DnsRecordClass)((responseBytes[offset++] << 8) + responseBytes[offset++]);
var ttl = (responseBytes[offset++] << 24) + (responseBytes[offset++] << 16) + (responseBytes[offset++] << 8) + responseBytes[offset++];
// Extract record data length
int dataLength = (responseBytes[offset] << 8) + responseBytes[offset + 1];
var dataLength = (responseBytes[offset] << 8) + responseBytes[offset + 1];
offset += 2;
// Extract record data
byte[] recordData = new byte[dataLength];
var recordData = new byte[dataLength];
Buffer.BlockCopy(responseBytes, offset, recordData, 0, dataLength);
string recordDataAsString = null;
@@ -295,9 +294,9 @@ namespace EonaCat.DnsTester.Helpers
recordDataAsString = DnsNameParser.ExtractDomainName(responseBytes, ref offset);
break;
case DnsRecordType.MX:
int preference = (responseBytes[0] << 8) + responseBytes[1];
var preference = (responseBytes[0] << 8) + responseBytes[1];
offset += 2;
string exchange = DnsNameParser.ExtractDomainName(responseBytes, ref offset);
var exchange = DnsNameParser.ExtractDomainName(responseBytes, ref offset);
recordDataAsString = $"{preference} {exchange}";
break;
case DnsRecordType.TXT:
@@ -320,8 +319,8 @@ namespace EonaCat.DnsTester.Helpers
static string GetString(byte[] bytes, ref int index, int length)
{
string str = "";
for (int i = 0; i < length; i++)
var str = "";
for (var i = 0; i < length; i++)
{
str += (char)bytes[index++];
}

View File

@@ -7,7 +7,7 @@ namespace EonaCat.DnsTester.Helpers
{
public static string ParseName(byte[] responseBytes, ref int offset)
{
List<string> labels = new List<string>();
var labels = new List<string>();
int length;
while ((length = responseBytes[offset++]) != 0)
@@ -15,8 +15,8 @@ namespace EonaCat.DnsTester.Helpers
if ((length & 0xC0) == 0xC0)
{
// The name is compressed
int pointer = ((length & 0x3F) << 8) | responseBytes[offset++];
int savedOffset = offset;
var pointer = ((length & 0x3F) << 8) | responseBytes[offset++];
var savedOffset = offset;
offset = pointer;
labels.AddRange(ParseName(responseBytes, ref offset).Split('.'));
offset = savedOffset;
@@ -24,7 +24,7 @@ namespace EonaCat.DnsTester.Helpers
}
// The name is not compressed
labels.Add(System.Text.Encoding.ASCII.GetString(responseBytes, offset, length));
labels.Add(Encoding.ASCII.GetString(responseBytes, offset, length));
offset += length;
}
@@ -33,11 +33,11 @@ namespace EonaCat.DnsTester.Helpers
public static string ExtractDomainName(byte[] buffer, ref int offset)
{
List<string> labels = new List<string>();
var labels = new List<string>();
while (true)
{
byte labelLength = buffer[offset++];
var labelLength = buffer[offset++];
if (labelLength == 0)
{
@@ -47,12 +47,12 @@ namespace EonaCat.DnsTester.Helpers
if ((labelLength & 0xC0) == 0xC0)
{
// Compressed domain name
int pointer = (int)(((labelLength & 0x3F) << 8) + buffer[offset++]);
var pointer = (int)(((labelLength & 0x3F) << 8) + buffer[offset++]);
labels.Add(ExtractDomainName(buffer, ref pointer));
break;
}
string label = Encoding.ASCII.GetString(buffer, offset, labelLength);
var label = Encoding.ASCII.GetString(buffer, offset, labelLength);
labels.Add(label);
offset += labelLength;
}

View File

@@ -1,7 +1,8 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -10,114 +11,147 @@ namespace EonaCat.DnsTester.Helpers
{
internal class UrlHelper
{
private static readonly RandomNumberGenerator _randomNumberGenerator = RandomNumberGenerator.Create();
private static readonly RandomNumberGenerator RandomNumberGenerator = RandomNumberGenerator.Create();
public static event EventHandler<string> Log;
private static async Task<List<string>> GetRandomUrls(int totalUrls)
public static bool UseSearchEngineYahoo { get; set; }
public static bool UseSearchEngineBing { get; set; }
public static bool UseSearchEngineGoogle { get; set; }
public static bool UseSearchEngineQwant { get; set; }
public static bool UseSearchEngineWolfram { get; set; }
public static bool UseSearchEngineStartPage { get; set; }
public static bool UseSearchEngineYandex { get; set; }
private static async Task<List<string>> GetRandomUrlsAsync(int totalUrls)
{
var urls = new ConcurrentDictionary<string, byte>();
var letters = GetRandomLetters();
var searchEngineUrls = GetSearchEngines().ToList();
var random = new Random();
while (urls.Count < totalUrls && searchEngineUrls.Count > 0)
{
var letters = GetRandomLetters();
Dictionary<string, string> searchEngineUrls = new Dictionary<string, string>
await Task.Run(async () =>
{
{ "Yahoo", "https://search.yahoo.com/search?p=" },
{ "Bing", "https://www.bing.com/search?q=" },
{ "Google", "https://www.google.com/search?q=" },
{ "Ask", "https://www.ask.com/web?q=" },
{ "WolframAlpha", "https://www.wolframalpha.com/input/?i=" },
{ "StartPage", "https://www.startpage.com/do/dsearch?query=" },
{ "Yandex", "https://www.yandex.com/search/?text=" },
{ "Qwant", "https://www.qwant.com/?q=" }
};
var index = random.Next(searchEngineUrls.Count);
var searchEngine = searchEngineUrls[index];
var url = searchEngine.Value + letters;
Random rand = new Random();
List<string> urls = new List<string>();
while (urls.Count < totalUrls)
{
int index = rand.Next(searchEngineUrls.Count);
KeyValuePair<string, string> searchEngine = searchEngineUrls.ElementAt(index);
string url = searchEngine.Value + letters;
using (var client = new WebClient())
try
{
string responseString = null;
try
{
responseString = client.DownloadString(url);
}
catch (Exception ex)
{
searchEngineUrls.Remove(searchEngine.Key);
SetStatus($"{searchEngine.Key}: {ex.Message}");
}
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(url).ConfigureAwait(false);
if (responseString == null)
if (response.IsSuccessStatusCode)
{
continue;
}
var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var hostNames = Regex.Matches(responseString, @"[.](\w+[.]com)");
// 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<string> uniqueNames = new HashSet<string>();
foreach (Match match in hostNames)
{
string name = match.Groups[1].Value;
if (name != $"{searchEngine.Key.ToLower()}.com")
foreach (Match match in hostNames)
{
uniqueNames.Add(name);
var name = match.Groups[1].Value;
if (name == $"{searchEngine.Key.ToLower()}.com") continue;
urls.TryAdd(name, 0); // TryAdd is thread-safe
if (urls.Count >= totalUrls)
{
break;
}
}
}
// Add the names to the list
foreach (string name in uniqueNames)
else
{
if (urls.Count >= totalUrls)
{
break;
}
if (!urls.Contains(name))
{
urls.Add(name);
}
searchEngineUrls.RemoveAt(index);
SetStatus($"{searchEngine.Key}: {response.StatusCode}");
}
httpClient.Dispose();
}
catch (Exception ex)
{
searchEngineUrls.RemoveAt(index);
SetStatus($"{searchEngine.Key}: {ex.Message}");
}
letters = GetRandomLetters();
await Task.Delay(100);
}
var urlText = "url" + (urls.Count > 1 ? "'s" : string.Empty);
SetStatus($"{urls.Count} random {urlText} found");
return urls;
await Task.Delay(100).ConfigureAwait(false);
}).ConfigureAwait(false);
}
public static async Task<List<string>> RetrieveUrls(int numThreads, int numUrlsPerThread)
var urlText = "url" + (urls.Count > 1 ? "'s" : string.Empty);
SetStatus($"{urls.Count} random {urlText} found");
return urls.Keys.ToList();
}
private static Dictionary<string, string> GetSearchEngines()
{
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++)
var searchEngineUrls = new Dictionary<string, string>();
if (UseSearchEngineYahoo)
{
tasks[i] = Task.Run(async () => urlList.AddRange(await GetRandomUrls(numUrlsPerThread)));
searchEngineUrls.Add("Yahoo", "https://search.yahoo.com/search?p=");
}
// wait for all threads to complete
await Task.WhenAll(tasks);
if (UseSearchEngineBing)
{
searchEngineUrls.Add("Bing", "https://www.bing.com/search?q=");
}
if (UseSearchEngineGoogle)
{
searchEngineUrls.Add("Google", "https://www.google.com/search?q=");
}
if (UseSearchEngineQwant)
{
searchEngineUrls.Add("Qwant", "https://www.qwant.com/?q=");
}
if (UseSearchEngineWolfram)
{
searchEngineUrls.Add("WolframAlpha", "https://www.wolframalpha.com/input/?i=");
}
if (UseSearchEngineStartPage)
{
searchEngineUrls.Add("StartPage", "https://www.startpage.com/do/dsearch?query=");
}
if (UseSearchEngineYandex)
{
searchEngineUrls.Add("Yandex", "https://www.yandex.com/search/?text=");
}
return searchEngineUrls;
}
public static async Task<List<string>> RetrieveUrlsAsync(int numThreads, int numUrlsPerThread)
{
var tasks = new List<Task<List<string>>>();
// Start each task to retrieve a subset of unique URLs
for (var i = 0; i < numThreads; i++)
{
tasks.Add(GetRandomUrlsAsync(numUrlsPerThread));
}
// Wait for all tasks to complete
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
// Flatten the results from all tasks into a single list
var urlList = results.SelectMany(urls => urls).ToList();
return urlList;
}
private static string GetRandomLetters()
{
// Generate a cryptographically strong random string
byte[] randomBytes = new byte[32];
_randomNumberGenerator.GetBytes(randomBytes);
var randomBytes = new byte[32];
RandomNumberGenerator.GetBytes(randomBytes);
return Convert.ToBase64String(randomBytes);
}

View File

@@ -30,7 +30,27 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
RunTest = new System.Windows.Forms.Button();
tabControl1 = new System.Windows.Forms.TabControl();
tabPage1 = new System.Windows.Forms.TabPage();
panel2 = new System.Windows.Forms.Panel();
checkBox8 = new System.Windows.Forms.CheckBox();
checkBox7 = new System.Windows.Forms.CheckBox();
checkBox6 = new System.Windows.Forms.CheckBox();
checkBox5 = new System.Windows.Forms.CheckBox();
checkBox3 = new System.Windows.Forms.CheckBox();
checkBox2 = new System.Windows.Forms.CheckBox();
checkBox1 = new System.Windows.Forms.CheckBox();
label4 = new System.Windows.Forms.Label();
StatusBox = new System.Windows.Forms.ListBox();
ResultView = new System.Windows.Forms.ListView();
Url = new System.Windows.Forms.ColumnHeader();
DNS1DATA = new System.Windows.Forms.ColumnHeader();
DNS1Performance = new System.Windows.Forms.ColumnHeader();
DNS2DATA = new System.Windows.Forms.ColumnHeader();
DNS2Performance = new System.Windows.Forms.ColumnHeader();
panel1 = new System.Windows.Forms.Panel();
numericUpDown2 = new System.Windows.Forms.NumericUpDown();
label2 = new System.Windows.Forms.Label();
comboBox1 = new System.Windows.Forms.ComboBox();
numericUpDown1 = new System.Windows.Forms.NumericUpDown();
label3 = new System.Windows.Forms.Label();
@@ -45,14 +65,7 @@
dnsList1 = new System.Windows.Forms.ComboBox();
lblDns2 = new System.Windows.Forms.Label();
lblDns1 = new System.Windows.Forms.Label();
panel2 = new System.Windows.Forms.Panel();
StatusBox = new System.Windows.Forms.ListBox();
ResultView = new System.Windows.Forms.ListView();
Url = new System.Windows.Forms.ColumnHeader();
DNS1DATA = new System.Windows.Forms.ColumnHeader();
DNS1Performance = new System.Windows.Forms.ColumnHeader();
DNS2DATA = new System.Windows.Forms.ColumnHeader();
DNS2Performance = new System.Windows.Forms.ColumnHeader();
tabPage2 = new System.Windows.Forms.TabPage();
panel3 = new System.Windows.Forms.Panel();
btnResolveHost = new System.Windows.Forms.Button();
btnResolveIP = new System.Windows.Forms.Button();
@@ -60,13 +73,14 @@
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();
tabControl1.SuspendLayout();
tabPage1.SuspendLayout();
panel2.SuspendLayout();
panel3.SuspendLayout();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit();
tabPage2.SuspendLayout();
panel3.SuspendLayout();
SuspendLayout();
//
// RunTest
@@ -77,13 +91,204 @@
RunTest.Name = "RunTest";
RunTest.Size = new System.Drawing.Size(435, 115);
RunTest.TabIndex = 12;
RunTest.Text = "Run Test";
RunTest.Text = "Execute";
RunTest.UseVisualStyleBackColor = false;
RunTest.Click += RunTest_Click;
//
// tabControl1
//
tabControl1.Controls.Add(tabPage1);
tabControl1.Controls.Add(tabPage2);
tabControl1.Location = new System.Drawing.Point(105, 0);
tabControl1.Name = "tabControl1";
tabControl1.SelectedIndex = 0;
tabControl1.Size = new System.Drawing.Size(2259, 1517);
tabControl1.TabIndex = 27;
//
// tabPage1
//
tabPage1.BackColor = System.Drawing.Color.LightGray;
tabPage1.Controls.Add(panel2);
tabPage1.Controls.Add(panel1);
tabPage1.Location = new System.Drawing.Point(10, 58);
tabPage1.Name = "tabPage1";
tabPage1.Padding = new System.Windows.Forms.Padding(3);
tabPage1.Size = new System.Drawing.Size(2239, 1449);
tabPage1.TabIndex = 0;
tabPage1.Text = "Dns tester";
//
// panel2
//
panel2.BackColor = System.Drawing.Color.Gold;
panel2.Controls.Add(checkBox8);
panel2.Controls.Add(checkBox7);
panel2.Controls.Add(checkBox6);
panel2.Controls.Add(checkBox5);
panel2.Controls.Add(checkBox3);
panel2.Controls.Add(checkBox2);
panel2.Controls.Add(checkBox1);
panel2.Controls.Add(label4);
panel2.Controls.Add(StatusBox);
panel2.Controls.Add(ResultView);
panel2.Location = new System.Drawing.Point(50, 510);
panel2.Name = "panel2";
panel2.Size = new System.Drawing.Size(2142, 905);
panel2.TabIndex = 27;
//
// checkBox8
//
checkBox8.AutoSize = true;
checkBox8.Checked = true;
checkBox8.CheckState = System.Windows.Forms.CheckState.Checked;
checkBox8.Location = new System.Drawing.Point(1172, 38);
checkBox8.Name = "checkBox8";
checkBox8.Size = new System.Drawing.Size(143, 45);
checkBox8.TabIndex = 70;
checkBox8.Text = "Qwant";
checkBox8.UseVisualStyleBackColor = true;
//
// checkBox7
//
checkBox7.AutoSize = true;
checkBox7.Checked = true;
checkBox7.CheckState = System.Windows.Forms.CheckState.Checked;
checkBox7.Location = new System.Drawing.Point(1172, 135);
checkBox7.Name = "checkBox7";
checkBox7.Size = new System.Drawing.Size(150, 45);
checkBox7.TabIndex = 69;
checkBox7.Text = "Yandex";
checkBox7.UseVisualStyleBackColor = true;
//
// checkBox6
//
checkBox6.AutoSize = true;
checkBox6.Checked = true;
checkBox6.CheckState = System.Windows.Forms.CheckState.Checked;
checkBox6.Location = new System.Drawing.Point(959, 135);
checkBox6.Name = "checkBox6";
checkBox6.Size = new System.Drawing.Size(181, 45);
checkBox6.TabIndex = 68;
checkBox6.Text = "StartPage";
checkBox6.UseVisualStyleBackColor = true;
//
// checkBox5
//
checkBox5.AutoSize = true;
checkBox5.Checked = true;
checkBox5.CheckState = System.Windows.Forms.CheckState.Checked;
checkBox5.Location = new System.Drawing.Point(659, 135);
checkBox5.Name = "checkBox5";
checkBox5.Size = new System.Drawing.Size(244, 45);
checkBox5.TabIndex = 67;
checkBox5.Text = "WolframAlpha";
checkBox5.UseVisualStyleBackColor = true;
//
// checkBox3
//
checkBox3.AutoSize = true;
checkBox3.Checked = true;
checkBox3.CheckState = System.Windows.Forms.CheckState.Checked;
checkBox3.Location = new System.Drawing.Point(959, 42);
checkBox3.Name = "checkBox3";
checkBox3.Size = new System.Drawing.Size(154, 45);
checkBox3.TabIndex = 65;
checkBox3.Text = "Google";
checkBox3.UseVisualStyleBackColor = true;
//
// checkBox2
//
checkBox2.AutoSize = true;
checkBox2.Checked = true;
checkBox2.CheckState = System.Windows.Forms.CheckState.Checked;
checkBox2.Location = new System.Drawing.Point(819, 41);
checkBox2.Name = "checkBox2";
checkBox2.Size = new System.Drawing.Size(115, 45);
checkBox2.TabIndex = 64;
checkBox2.Text = "Bing";
checkBox2.UseVisualStyleBackColor = true;
//
// checkBox1
//
checkBox1.AutoSize = true;
checkBox1.Checked = true;
checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
checkBox1.Location = new System.Drawing.Point(659, 42);
checkBox1.Name = "checkBox1";
checkBox1.Size = new System.Drawing.Size(138, 45);
checkBox1.TabIndex = 63;
checkBox1.Text = "Yahoo";
checkBox1.UseVisualStyleBackColor = true;
//
// label4
//
label4.AutoSize = true;
label4.Location = new System.Drawing.Point(56, 42);
label4.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
label4.Name = "label4";
label4.Size = new System.Drawing.Size(472, 41);
label4.TabIndex = 62;
label4.Text = "Use searchengines for url retrieval:";
label4.Visible = false;
//
// StatusBox
//
StatusBox.BackColor = System.Drawing.Color.OldLace;
StatusBox.FormattingEnabled = true;
StatusBox.HorizontalScrollbar = true;
StatusBox.ItemHeight = 41;
StatusBox.Location = new System.Drawing.Point(56, 741);
StatusBox.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
StatusBox.Name = "StatusBox";
StatusBox.Size = new System.Drawing.Size(2051, 127);
StatusBox.TabIndex = 25;
//
// ResultView
//
ResultView.BackColor = System.Drawing.Color.OldLace;
ResultView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { Url, DNS1DATA, DNS1Performance, DNS2DATA, DNS2Performance });
ResultView.GridLines = true;
ResultView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
ResultView.Location = new System.Drawing.Point(56, 214);
ResultView.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
ResultView.MultiSelect = false;
ResultView.Name = "ResultView";
ResultView.Size = new System.Drawing.Size(2051, 487);
ResultView.TabIndex = 24;
ResultView.UseCompatibleStateImageBehavior = false;
ResultView.View = System.Windows.Forms.View.Details;
//
// Url
//
Url.Text = "URL";
Url.Width = 160;
//
// DNS1DATA
//
DNS1DATA.Text = "Data";
DNS1DATA.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS1DATA.Width = 140;
//
// DNS1Performance
//
DNS1Performance.Text = "Performance";
DNS1Performance.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS1Performance.Width = 120;
//
// DNS2DATA
//
DNS2DATA.Text = "Data";
DNS2DATA.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS2DATA.Width = 140;
//
// DNS2Performance
//
DNS2Performance.Text = "Performance";
DNS2Performance.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS2Performance.Width = 120;
//
// panel1
//
panel1.BackColor = System.Drawing.SystemColors.ControlLight;
panel1.BackColor = System.Drawing.Color.Gold;
panel1.Controls.Add(numericUpDown2);
panel1.Controls.Add(label2);
panel1.Controls.Add(comboBox1);
@@ -100,19 +305,40 @@
panel1.Controls.Add(dnsList1);
panel1.Controls.Add(lblDns2);
panel1.Controls.Add(lblDns1);
panel1.Location = new System.Drawing.Point(155, 294);
panel1.Location = new System.Drawing.Point(50, 49);
panel1.Name = "panel1";
panel1.Size = new System.Drawing.Size(2209, 396);
panel1.TabIndex = 24;
panel1.Size = new System.Drawing.Size(2142, 396);
panel1.TabIndex = 26;
//
// 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 });
//
// 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:";
//
// comboBox1
//
comboBox1.ForeColor = System.Drawing.Color.Black;
comboBox1.FormattingEnabled = true;
comboBox1.Items.AddRange(new object[] { "A", "NS", "CNAME", "MX", "TXT" });
comboBox1.Location = new System.Drawing.Point(1583, 71);
comboBox1.Name = "comboBox1";
comboBox1.Size = new System.Drawing.Size(302, 49);
comboBox1.TabIndex = 59;
comboBox1.Text = "Select record type";
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
//
// numericUpDown1
@@ -163,7 +389,7 @@
// CustomDns2
//
CustomDns2.Enabled = false;
CustomDns2.Location = new System.Drawing.Point(1318, 297);
CustomDns2.Location = new System.Drawing.Point(1317, 289);
CustomDns2.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
CustomDns2.Name = "CustomDns2";
CustomDns2.Size = new System.Drawing.Size(668, 47);
@@ -184,7 +410,7 @@
// lblCustom2
//
lblCustom2.AutoSize = true;
lblCustom2.Location = new System.Drawing.Point(1065, 301);
lblCustom2.Location = new System.Drawing.Point(1064, 293);
lblCustom2.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
lblCustom2.Name = "lblCustom2";
lblCustom2.Size = new System.Drawing.Size(219, 41);
@@ -206,7 +432,7 @@
// UseCustomServers
//
UseCustomServers.AutoSize = true;
UseCustomServers.Location = new System.Drawing.Point(1723, 147);
UseCustomServers.Location = new System.Drawing.Point(1071, 224);
UseCustomServers.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
UseCustomServers.Name = "UseCustomServers";
UseCustomServers.Size = new System.Drawing.Size(262, 45);
@@ -224,6 +450,7 @@
dnsList2.Name = "dnsList2";
dnsList2.Size = new System.Drawing.Size(320, 49);
dnsList2.TabIndex = 38;
dnsList2.Text = "Select Dns2";
//
// dnsList1
//
@@ -234,6 +461,7 @@
dnsList1.Name = "dnsList1";
dnsList1.Size = new System.Drawing.Size(451, 49);
dnsList1.TabIndex = 37;
dnsList1.Text = "Select Dns 1";
//
// lblDns2
//
@@ -255,69 +483,16 @@
lblDns1.TabIndex = 35;
lblDns1.Text = "Dns 1:";
//
// panel2
// tabPage2
//
panel2.BackColor = System.Drawing.SystemColors.ControlLight;
panel2.Controls.Add(StatusBox);
panel2.Controls.Add(ResultView);
panel2.Location = new System.Drawing.Point(145, 765);
panel2.Name = "panel2";
panel2.Size = new System.Drawing.Size(2219, 745);
panel2.TabIndex = 25;
//
// StatusBox
//
StatusBox.FormattingEnabled = true;
StatusBox.HorizontalScrollbar = true;
StatusBox.ItemHeight = 41;
StatusBox.Location = new System.Drawing.Point(56, 571);
StatusBox.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
StatusBox.Name = "StatusBox";
StatusBox.Size = new System.Drawing.Size(2126, 127);
StatusBox.TabIndex = 25;
//
// ResultView
//
ResultView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { Url, DNS1DATA, DNS1Performance, DNS2DATA, DNS2Performance });
ResultView.GridLines = true;
ResultView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
ResultView.Location = new System.Drawing.Point(56, 49);
ResultView.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
ResultView.MultiSelect = false;
ResultView.Name = "ResultView";
ResultView.Size = new System.Drawing.Size(2126, 487);
ResultView.TabIndex = 24;
ResultView.UseCompatibleStateImageBehavior = false;
ResultView.View = System.Windows.Forms.View.Details;
//
// Url
//
Url.Text = "URL";
Url.Width = 160;
//
// DNS1DATA
//
DNS1DATA.Text = "Data";
DNS1DATA.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS1DATA.Width = 140;
//
// DNS1Performance
//
DNS1Performance.Text = "Performance";
DNS1Performance.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS1Performance.Width = 120;
//
// DNS2DATA
//
DNS2DATA.Text = "Data";
DNS2DATA.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS2DATA.Width = 140;
//
// DNS2Performance
//
DNS2Performance.Text = "Performance";
DNS2Performance.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS2Performance.Width = 120;
tabPage2.Controls.Add(panel3);
tabPage2.Location = new System.Drawing.Point(10, 58);
tabPage2.Name = "tabPage2";
tabPage2.Padding = new System.Windows.Forms.Padding(3);
tabPage2.Size = new System.Drawing.Size(2239, 1449);
tabPage2.TabIndex = 1;
tabPage2.Text = "Resolve clients";
tabPage2.UseVisualStyleBackColor = true;
//
// panel3
//
@@ -328,10 +503,10 @@
panel3.Controls.Add(txtResolveIP);
panel3.Controls.Add(label5);
panel3.Controls.Add(label1);
panel3.Location = new System.Drawing.Point(155, 45);
panel3.Location = new System.Drawing.Point(15, 12);
panel3.Name = "panel3";
panel3.Size = new System.Drawing.Size(2209, 175);
panel3.TabIndex = 26;
panel3.TabIndex = 28;
//
// btnResolveHost
//
@@ -385,35 +560,15 @@
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);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
AutoSize = true;
AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
BackColor = System.Drawing.SystemColors.MenuHighlight;
ClientSize = new System.Drawing.Size(2517, 1693);
Controls.Add(panel3);
Controls.Add(panel2);
Controls.Add(panel1);
Controls.Add(tabControl1);
Controls.Add(RunTest);
Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon");
Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
@@ -422,19 +577,35 @@
StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
Text = "EonaCat.DnsTester";
Load += TesterUI_Load;
tabControl1.ResumeLayout(false);
tabPage1.ResumeLayout(false);
panel2.ResumeLayout(false);
panel2.PerformLayout();
panel1.ResumeLayout(false);
panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit();
panel2.ResumeLayout(false);
tabPage2.ResumeLayout(false);
panel3.ResumeLayout(false);
panel3.PerformLayout();
((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit();
ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button RunTest;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.ListBox StatusBox;
private System.Windows.Forms.ListView ResultView;
private System.Windows.Forms.ColumnHeader Url;
private System.Windows.Forms.ColumnHeader DNS1DATA;
private System.Windows.Forms.ColumnHeader DNS1Performance;
private System.Windows.Forms.ColumnHeader DNS2DATA;
private System.Windows.Forms.ColumnHeader DNS2Performance;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label3;
@@ -449,14 +620,7 @@
private System.Windows.Forms.ComboBox dnsList1;
private System.Windows.Forms.Label lblDns2;
private System.Windows.Forms.Label lblDns1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.ListBox StatusBox;
private System.Windows.Forms.ListView ResultView;
private System.Windows.Forms.ColumnHeader Url;
private System.Windows.Forms.ColumnHeader DNS1DATA;
private System.Windows.Forms.ColumnHeader DNS1Performance;
private System.Windows.Forms.ColumnHeader DNS2DATA;
private System.Windows.Forms.ColumnHeader DNS2Performance;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Button btnResolveHost;
private System.Windows.Forms.Button btnResolveIP;
@@ -464,8 +628,14 @@
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;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox3;
private System.Windows.Forms.CheckBox checkBox8;
private System.Windows.Forms.CheckBox checkBox7;
private System.Windows.Forms.CheckBox checkBox6;
private System.Windows.Forms.CheckBox checkBox5;
}
}

View File

@@ -37,27 +37,43 @@ namespace EonaCat.DnsTester
}
}
if (_useCustomDnsServers && (!chkDns1.Checked || chkDns2.Checked))
if (_useCustomDnsServers && (!chkDns1.Checked && !chkDns2.Checked))
{
MessageBox.Show("Please enable DNS 1 or 2 before using custom Dns");
return;
}
List<string> urls = new List<string>();
SetupView();
var numThreads = (int)numericUpDown2.Value; // number of concurrent threads to use
var maxUrls = (int)numericUpDown1.Value; // maximum number of unique URLs to retrieve
var numUrlsPerThread = maxUrls / numThreads;
if (numUrlsPerThread == 0)
{
numUrlsPerThread = maxUrls;
numThreads = 1;
}
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);
SetSearchEngines();
var urls = await UrlHelper.RetrieveUrlsAsync(numThreads, numUrlsPerThread).ConfigureAwait(false);
AddUrlToView(urls);
IsRunning = true;
await Process(_recordType, urls.ToArray(), _dnsServer1, _dnsServer2);
RunTest.Invoke(() => { RunTest.Enabled = false; });
await ProcessAsync(_recordType, urls.ToArray(), _dnsServer1, _dnsServer2).ConfigureAwait(false);
IsRunning = false;
RunTest.Invoke(() => { RunTest.Enabled = true; });
}
private void SetSearchEngines()
{
UrlHelper.UseSearchEngineYahoo = checkBox1.Checked;
UrlHelper.UseSearchEngineBing = checkBox2.Checked;
UrlHelper.UseSearchEngineGoogle = checkBox3.Checked;
UrlHelper.UseSearchEngineQwant = checkBox8.Checked;
UrlHelper.UseSearchEngineWolfram = checkBox5.Checked;
UrlHelper.UseSearchEngineStartPage = checkBox6.Checked;
UrlHelper.UseSearchEngineYandex = checkBox7.Checked;
}
private void SetupView()
@@ -109,23 +125,26 @@ namespace EonaCat.DnsTester
private void AddUrlToView(List<string> urls)
{
foreach (var currentUrl in urls)
ResultView.Invoke(() =>
{
ListViewItem listURL = new ListViewItem(currentUrl);
listURL.SubItems.Add(" ");
listURL.SubItems.Add(" ");
listURL.SubItems.Add(" ");
listURL.SubItems.Add(" ");
foreach (var currentUrl in urls)
{
var listUrl = new ListViewItem(currentUrl);
listUrl.SubItems.Add(" ");
listUrl.SubItems.Add(" ");
listUrl.SubItems.Add(" ");
listUrl.SubItems.Add(" ");
ResultView.Items.Add(listURL);
}
ResultView.Items.Add(listUrl);
}
if (ResultView.Items.Count > 1)
{
ResultView.EnsureVisible(ResultView.Items.Count - 1);
}
if (ResultView.Items.Count > 1)
{
ResultView.EnsureVisible(ResultView.Items.Count - 1);
}
ResultView.Update();
ResultView.Update();
});
Application.DoEvents();
}
@@ -144,13 +163,13 @@ namespace EonaCat.DnsTester
dnsList2.DisplayMember = "name";
var serverList = Path.Combine(Application.StartupPath, "Servers.xml");
DataSet servers1 = new DataSet();
DataSet servers2 = new DataSet();
var servers1 = new DataSet();
var servers2 = new DataSet();
servers1.ReadXml(serverList);
servers2.ReadXml(serverList);
DataTable dataTable1 = servers1.Tables[0];
DataTable dataTable2 = servers2.Tables[0];
var dataTable1 = servers1.Tables[0];
var dataTable2 = servers2.Tables[0];
dnsList1.DataSource = dataTable1;
dnsList2.DataSource = dataTable2;
}
@@ -177,44 +196,46 @@ namespace EonaCat.DnsTester
}
private async Task Process(DnsRecordType recordType, string[] urls, string dnsAddress1, string dnsAddress2)
private async Task ProcessAsync(DnsRecordType recordType, string[] urls, string dnsAddress1, string dnsAddress2)
{
if (recordType == 0)
{
recordType = DnsRecordType.A;
}
int urlsTotal = urls.Length;
var urlsTotal = urls.Length;
const string dnsId1 = "Dns1";
const string dnsId2 = "Dns2";
DnsHelper.OnLog -= DnsHelper_OnLog;
DnsHelper.OnLog += DnsHelper_OnLog;
for (int i = 0; i < urlsTotal; i++)
for (var i = 0; i < urlsTotal; 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);
await ExecuteDns1Async(recordType, dnsAddress1, currentUrl, dnsId1, i).ConfigureAwait(false);
if (chkDns2.Checked)
{
await ExecuteDns2Async(recordType, dnsAddress2, currentUrl, dnsId2, i).ConfigureAwait(false);
}
await Task.Delay(100).ConfigureAwait(false);
}
}
private async Task ExecuteDns2(DnsRecordType recordType, string dnsAddress2, string currentUrl, string dnsId2,
private async Task ExecuteDns2Async(DnsRecordType recordType, string dnsAddress2, string currentUrl, string dnsId2,
int i)
{
try
{
DnsResponse response2 = null;
byte[] queryBytes2 = DnsHelper.CreateDnsQueryPacket(currentUrl, recordType);
response2 = await DnsHelper.SendDnsQueryPacket(dnsId2, dnsAddress2, 53, queryBytes2);
var queryBytes2 = DnsHelper.CreateDnsQueryPacket(currentUrl, recordType);
response2 = await DnsHelper.SendDnsQueryPacketAsync(dnsId2, dnsAddress2, 53, queryBytes2).ConfigureAwait(false);
ProcessResponse(response2);
}
catch (SocketException socketException)
{
SetStatus(
Convert.ToString(socketException).IndexOf("time", StringComparison.Ordinal) > 0
Convert.ToString(socketException)!.IndexOf("time", StringComparison.Ordinal) > 0
? $"DNS1 Timeout - No response received for {Convert.ToString(DnsHelper.DnsReceiveTimeout / 1000)} seconds"
: Convert.ToString(socketException));
}
@@ -225,7 +246,7 @@ namespace EonaCat.DnsTester
}
}
private async Task ExecuteDns1(DnsRecordType recordType, string dnsAddress1, string currentUrl, string dnsId1,
private async Task ExecuteDns1Async(DnsRecordType recordType, string dnsAddress1, string currentUrl, string dnsId1,
int i)
{
if (chkDns1.Checked)
@@ -233,14 +254,14 @@ namespace EonaCat.DnsTester
try
{
DnsResponse response1 = null;
byte[] queryBytes1 = DnsHelper.CreateDnsQueryPacket(currentUrl, recordType);
response1 = await DnsHelper.SendDnsQueryPacket(dnsId1, dnsAddress1, 53, queryBytes1);
var queryBytes1 = DnsHelper.CreateDnsQueryPacket(currentUrl, recordType);
response1 = await DnsHelper.SendDnsQueryPacketAsync(dnsId1, dnsAddress1, 53, queryBytes1).ConfigureAwait(false);
ProcessResponse(response1);
}
catch (SocketException socketException)
{
SetStatus(
Convert.ToString(socketException).IndexOf("time", StringComparison.Ordinal) > 0
Convert.ToString(socketException)!.IndexOf("time", StringComparison.Ordinal) > 0
? $"DNS1 Timeout - No response received for {Convert.ToString(DnsHelper.DnsReceiveTimeout / 1000)} seconds"
: Convert.ToString(socketException));
}
@@ -259,7 +280,7 @@ namespace EonaCat.DnsTester
private void ProcessResponse(DnsResponse dnsResponse)
{
if (dnsResponse?.Answers == null || !dnsResponse.Answers.Any())
if (dnsResponse == null || dnsResponse?.Answers == null || !dnsResponse.Answers.Any())
{
return;
}
@@ -276,7 +297,7 @@ namespace EonaCat.DnsTester
ResultView.Invoke(() =>
{
for (int i = 0; i < ResultView.Items.Count; i++)
for (var i = 0; i < ResultView.Items.Count; i++)
{
foreach (var answer in dnsResponse.Answers)
{
@@ -288,7 +309,7 @@ namespace EonaCat.DnsTester
{
case "Dns1":
ResultView.Items[i].SubItems[1].Text =
Convert.ToString(answer.Data);
Convert.ToString(answer.Data) ?? string.Empty;
sDeltaTime = Convert.ToString(deltaTime);
ResultView.Items[i].SubItems[2].Text =
sDeltaTime.Length > 5 ? sDeltaTime.Substring(0, 5) : sDeltaTime;
@@ -301,7 +322,7 @@ namespace EonaCat.DnsTester
case "Dns2":
ResultView.Items[i].SubItems[3].Text =
Convert.ToString(answer.Data);
Convert.ToString(answer.Data) ?? string.Empty;
sDeltaTime = Convert.ToString(deltaTime);
ResultView.Items[i].SubItems[4].Text =
sDeltaTime.Length > 5 ? sDeltaTime.Substring(0, 5) : sDeltaTime;
@@ -325,7 +346,7 @@ namespace EonaCat.DnsTester
return;
}
if (!IPAddress.TryParse(txtResolveIP.Text, out IPAddress iPAddress))
if (!IPAddress.TryParse(txtResolveIP.Text, out var iPAddress))
{
MessageBox.Show("Please enter a valid IP address");
return;
@@ -337,15 +358,15 @@ namespace EonaCat.DnsTester
{
var dnsEntry = Dns.GetHostEntry(iPAddress);
txtResolveHost.Invoke(() =>
{
txtResolveHost.Text = dnsEntry.HostName;
});
{
txtResolveHost.Text = dnsEntry.HostName;
});
}
catch (Exception)
{
MessageBox.Show($"Could not get hostname for IP address '{txtResolveIP.Text}'");
}
});
}).ConfigureAwait(false);
}
private async void btnResolveHost_Click(object sender, EventArgs e)
@@ -364,15 +385,15 @@ namespace EonaCat.DnsTester
var dnsEntry = Dns.GetHostEntry(txtResolveHost.Text);
txtResolveHost.Invoke(() =>
{
txtResolveIP.Text = dnsEntry.AddressList.Where(x => x.AddressFamily == AddressFamily.InterNetwork).FirstOrDefault().Address.ToString();
});
{
txtResolveIP.Text = dnsEntry.AddressList.Where(x => x.AddressFamily == AddressFamily.InterNetwork).FirstOrDefault().Address.ToString();
});
}
catch (Exception)
{
MessageBox.Show($"Could not get IP address for hostname '{txtResolveHost.Text}'");
}
});
}).ConfigureAwait(false);
}
private void SetStatus(string text)
@@ -409,5 +430,20 @@ namespace EonaCat.DnsTester
{
SetUI();
}
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
UrlHelper.UseSearchEngineYahoo = checkBox1.Checked;
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
UrlHelper.UseSearchEngineBing = checkBox2.Checked;
}
}
}

View File

@@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">

View File

@@ -2,25 +2,30 @@
<Servers>
<!-- My Local Blocky Dns -->
<server name="Local Blocky" ip="127.0.0.1"></server>
<!-- My External Blocky Dns -->
<server name="External Blocky" ip="192.168.1.10"></server>
<!-- My Remote Blocky Dns -->
<server name="Remote Blocky" ip="192.168.1.254"></server>
<!--AdGuard DNS-->
<!--AdGuard Dns servers-->
<server name="AdGuard Dns (94.140.14.15)" ip="94.140.14.15"></server>
<server name="AdGuard Dns (94.140.15.15)" ip="94.140.15.15"></server>
<!--Verisign-->
<server name="Verisign (64.6.64.6)" ip="64.6.64.6"></server>
<server name="Verisign (64.6.65.6)" ip="64.6.65.6"></server>
<!--Google Dns Servers-->
<server name="Google (8.8.8.8)" ip="8.8.8.8"></server>
<server name="Google (8.8.4.4)" ip="8.8.8.8"></server>
<!--CloudFlare Dns servers-->
<server name="CloudFlare Standard (1.1.1.1)" ip="1.1.1.1"></server>
<server name="CloudFlare Standard (1.0.0.1)" ip="1.0.0.1"></server>
<!--Quad9 DNS-->
<!--Google Dns servers-->
<server name="Google (8.8.8.8)" ip="8.8.8.8"></server>
<server name="Google (8.8.4.4)" ip="8.8.4.4"></server>
<!--Quad9 Dns servers-->
<server name="Quad9 Dns 1 (9.9.9.9)" ip="9.9.9.9"></server>
<server name="Quad9 Dns 2 (149.112.112.9)" ip="149.112.112.9"></server>
<!--Verisign Dns servers-->
<server name="Verisign (64.6.64.6)" ip="64.6.64.6"></server>
<server name="Verisign (64.6.65.6)" ip="64.6.65.6"></server>
</Servers>

View File

@@ -6,4 +6,8 @@ Dns Testing tool for Blocky
https://blocky.EonaCat.com
https://www.nuget.org/packages/EonaCat.Blocky
https://www.nuget.org/packages/EonaCat.Dns
[![EonaCat DnsTester](https://github.com/EonaCat/EonaCat.DnsTester/blob/main/Screenshots/1.png?raw=true "EonaCat DnsTester")](https://github.com/EonaCat/EonaCat.DnsTester/blob/main/Screenshots/1.png?raw=true "EonaCat DnsTester")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 KiB

After

Width:  |  Height:  |  Size: 538 KiB