This commit is contained in:
EonaCat 2023-02-27 22:15:41 +01:00
parent 2ba9705b66
commit 150a3f226b
11 changed files with 863 additions and 532 deletions

View File

@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="EonaCat.DnsTester.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<userSettings>
<EonaCat.DnsTester.Properties.Settings>
<setting name="EonaCat" serializeAs="String">
<value />
</setting>
</EonaCat.DnsTester.Properties.Settings>
</userSettings>
</configuration>

View File

@ -14,4 +14,19 @@
<ItemGroup>
<Content Include="EonaCat.ico" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>

View File

@ -1,118 +1,400 @@
using Microsoft.VisualBasic.Logging;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EonaCat.DnsTester.Helpers
{
internal class DnsHelper
class DnsHelper
{
public static event EventHandler<string> Log;
public static void ProcessDns(string startOfUrl, string domain, int urlsTotal, Socket dnsSocket, byte[] bytesSend,
long startTime, int totalDnsToUse, ListView result)
public static event EventHandler<string> OnLog;
public static async Task<DnsResponse> SendDnsQueryPacket(string dnsId, string server, int port, byte[] queryBytes)
{
var bytesReceived = new byte[512];
var totalReceived = 0;
// Start the clock
var startTime = DateTime.Now.Ticks;
// wait for a response up to timeout
while (totalReceived < urlsTotal * totalDnsToUse)
var endPoint = new IPEndPoint(IPAddress.Parse(server), port);
using (var client = new UdpClient(endPoint.AddressFamily))
{
dnsSocket.Receive(bytesReceived);
// Check if the error is ours
if ((bytesReceived[0] != bytesSend[0] || bytesReceived[1] != 0x31) &&
bytesReceived[1] != 0x32)
continue;
if (bytesReceived[2] != 0x81 || bytesReceived[3] != 0x80) continue;
// Get the time now
var stopTime = DateTime.Now.Ticks;
var deltaTime = Convert.ToString((double)(stopTime - startTime) / 10000000);
// Decode the answers
// Find the URL that was returned
int dnsId = bytesReceived[1];
var receiveString = Encoding.ASCII.GetString(bytesReceived);
var index = 12;
int startOfUrlLength = bytesReceived[index];
index++;
startOfUrl = receiveString.Substring(index, startOfUrlLength);
index += startOfUrlLength;
int domainLength = bytesReceived[index];
index++;
domain = receiveString.Substring(index, domainLength);
index += domainLength;
index += 8;
// Get the record type
int ResponseType = bytesReceived[index];
index += 9;
// Get the IP address if applicable
var ipResponse = "";
switch (ResponseType)
{
case 1:
ipResponse =
$"{Convert.ToString(bytesReceived[index])}.{Convert.ToString(bytesReceived[index + 1])}.{Convert.ToString(bytesReceived[index + 2])}.{Convert.ToString(bytesReceived[index + 3])}";
break;
case 5:
ipResponse = "CNAME";
break;
case 6:
ipResponse = "SOA";
break;
}
SetStatus($"Answer: {startOfUrl}.{domain} : {ipResponse}");
// Find the url in the list
for (int i = 0; i < result.Items.Count; i++)
{
if (result.Items[i].Text != $"{startOfUrl}.{domain}") continue;
string sDeltaTime;
switch (dnsId)
{
case 49:
result.Items[i].SubItems[1].Text = Convert.ToString(ipResponse);
sDeltaTime = Convert.ToString(deltaTime);
result.Items[i].SubItems[2].Text =
sDeltaTime.Length > 5 ? sDeltaTime.Substring(0, 5) : sDeltaTime;
result.Items[i].ForeColor = System.Drawing.Color.Red;
result.EnsureVisible(i);
result.Update();
Application.DoEvents();
result.Items[i].ForeColor = System.Drawing.Color.Black;
break;
case 50:
result.Items[i].SubItems[3].Text = Convert.ToString(ipResponse);
sDeltaTime = Convert.ToString(deltaTime);
result.Items[i].SubItems[4].Text =
sDeltaTime.Length > 5 ? sDeltaTime.Substring(0, 5) : sDeltaTime;
result.Items[i].ForeColor = System.Drawing.Color.Red;
result.EnsureVisible(i);
result.Update();
Application.DoEvents();
result.Items[i].ForeColor = System.Drawing.Color.Black;
break;
}
totalReceived++;
}
client.DontFragment = true;
client.EnableBroadcast = false;
client.Client.ReceiveTimeout = DnsReceiveTimeout;
await client.SendAsync(queryBytes, queryBytes.Length, endPoint);
var responseResult = await client.ReceiveAsync();
DnsResponse response = ParseDnsResponsePacket(dnsId, startTime, server, responseResult.Buffer);
return response;
}
}
private static void SetStatus(string text)
public static int DnsReceiveTimeout { get; set; } = 5;
public static byte[] CreateDnsQueryPacket(string domainName, DnsRecordType recordType)
{
Log?.Invoke(null, text);
Random random = new Random();
// DNS header
ushort id = (ushort)random.Next(0, 65536);
ushort flags = (ushort)0x0100; // recursion desired
ushort qdcount = 1;
ushort ancount = 0;
ushort nscount = 0;
ushort arcount = 0;
byte[] headerBytes = new byte[]
{
(byte)(id >> 8), (byte)(id & 0xff),
(byte)(flags >> 8), (byte)(flags & 0xff),
(byte)(qdcount >> 8), (byte)(qdcount & 0xff),
(byte)(ancount >> 8), (byte)(ancount & 0xff),
(byte)(nscount >> 8), (byte)(nscount & 0xff),
(byte)(arcount >> 8), (byte)(arcount & 0xff),
};
// DNS question
string[] labels = domainName.Split('.');
byte[] qnameBytes = new byte[domainName.Length + 2];
int qnameIndex = 0;
foreach (string label in labels)
{
qnameBytes[qnameIndex++] = (byte)label.Length;
foreach (char 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];
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];
headerBytes.CopyTo(queryBytes, 0);
questionBytes.CopyTo(queryBytes, headerBytes.Length);
return queryBytes;
}
static DnsQuestion ParseDnsQuestionRecord(byte[] queryBytes, ref int offset)
{
// Parse the DNS name
string name = ParseDnsName(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]);
offset += 4;
return new DnsQuestion
{
Name = name,
Type = (DnsRecordType)type,
Class = (DnsRecordClass)qclass,
};
}
static DnsResponse ParseDnsResponsePacket(string dnsId, long startTime, string server, byte[] responseBytes)
{
// Parse the DNS header
ushort id = (ushort)((responseBytes[0] << 8) | responseBytes[1]);
ushort flags = (ushort)((responseBytes[2] << 8) | responseBytes[3]);
ushort qdcount = (ushort)((responseBytes[4] << 8) | responseBytes[5]);
ushort ancount = (ushort)((responseBytes[6] << 8) | responseBytes[7]);
ushort nscount = (ushort)((responseBytes[8] << 8) | responseBytes[9]);
ushort arcount = (ushort)((responseBytes[10] << 8) | responseBytes[11]);
List<DnsQuestion> questions = new List<DnsQuestion>();
//for (int i = 0; i < qdcount; i++)
//{
// DnsQuestion question = ParseDnsQuestionRecord(responseBytes, ref offset);
// if (question != null)
// {
// questions.Add(question);
// }
//}
int offset = 12;
// Parse the DNS answer records
List<ResourceRecord> answers = new List<ResourceRecord>();
for (int i = 0; i < ancount; i++)
{
try
{
ResourceRecord answer = ParseDnsAnswerRecord(responseBytes, ref offset);
if (answer != null)
{
answers.Add(answer);
}
}
catch (Exception exception)
{
OnLog?.Invoke(null, $"Answer exception: " + exception.Message);
}
}
// Parse the DNS authority records
List<ResourceRecord> authorities = new List<ResourceRecord>();
for (int i = 0; i < nscount; i++)
{
try
{
ResourceRecord authority = ParseDnsAnswerRecord(responseBytes, ref offset);
if (authority != null)
{
authorities.Add(authority);
}
}
catch (Exception exception)
{
OnLog?.Invoke(null, $"Authority answer exception: " + exception.Message);
}
}
// Parse the DNS additional records
List<ResourceRecord> additionals = new List<ResourceRecord>();
for (int i = 0; i < arcount; i++)
{
try
{
ResourceRecord additional = ParseDnsAnswerRecord(responseBytes, ref offset);
if (additional != null)
{
additionals.Add(additional);
}
}
catch (Exception exception)
{
OnLog?.Invoke(null, $"Additional answer exception: " + exception.Message);
}
}
return new DnsResponse
{
Id = id,
StartTime = startTime,
Resolver = server,
Flags = flags,
Class = (DnsRecordClass)((flags >> 3) & 0x0f),
DnsId = dnsId,
Questions = questions,
Answers = answers,
Authorities = authorities,
Additionals = additionals,
};
}
static ResourceRecord ParseDnsAnswerRecord(byte[] responseBytes, ref int offset)
{
// Parse the DNS name
string name = ParseDnsName(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++]);
uint ttl = (uint)((responseBytes[offset++] << 24) | (responseBytes[offset++] << 16) | (responseBytes[offset++] << 8) | responseBytes[offset++]);
ushort rdlen = (ushort)((responseBytes[responseBytes.Length - 5]));
offset += 10;
// Parse the DNS data
string data = null;
switch ((DnsRecordType)type)
{
case DnsRecordType.A:
if (rdlen != 4)
{
return null;
}
data = new IPAddress(new byte[]
{
responseBytes[offset], responseBytes[offset + 1], responseBytes[offset + 2],
responseBytes[offset + 3]
}).ToString();
offset += rdlen;
break;
case DnsRecordType.CNAME:
case DnsRecordType.NS:
data = ParseDnsName(responseBytes, ref offset);
if (data == null)
{
return null;
}
break;
case DnsRecordType.MX:
ushort preference = (ushort)((responseBytes[offset] << 8) | responseBytes[offset + 1]);
offset += 2;
string exchange = ParseDnsName(responseBytes, ref offset);
if (exchange == null)
{
return null;
}
data = $"{preference} {exchange}";
break;
case DnsRecordType.TXT:
data = Encoding.ASCII.GetString(responseBytes, offset, rdlen);
offset += rdlen;
break;
default:
offset += rdlen;
break;
}
return new ResourceRecord
{
Name = name,
Type = type,
Class = klass,
Ttl = TimeSpan.FromSeconds(ttl),
Data = data,
};
}
static string ParseDnsName(byte[] responseBytes, ref int offset)
{
StringBuilder name = new StringBuilder();
int originalOffset = offset;
while (true)
{
byte len = responseBytes[offset++];
if (len == 0)
{
break;
}
if ((len & 0xc0) == 0xc0)
{
ushort pointer = (ushort)(((len & 0x3f) << 8) | responseBytes[offset++]);
int pointerOffset = pointer & 0x3fff;
if (pointerOffset >= responseBytes.Length)
{
return null;
}
int pointerEnd = offset;
offset = pointerOffset;
if (offset < originalOffset)
{
return null;
}
name.Append(ParseDnsName(responseBytes, ref offset));
offset = pointerEnd;
break;
}
if (len > 63)
{
return null;
}
name.Append(Encoding.ASCII.GetString(responseBytes, offset, len));
offset += len;
if (responseBytes[offset - 1] != 0)
{
name.Append(".");
}
}
if (originalOffset == offset)
{
return null;
}
return name.ToString();
}
}
public class DnsQuestion
{
public string Name { get; set; }
public DnsRecordType Type { get; set; }
public DnsRecordClass Class { get; set; }
}
public class ResourceRecord
{
public string Name { get; set; }
public DnsRecordType Type { get; set; }
public string Data { get; set; }
public DnsRecordClass Class { get; set; }
public TimeSpan Ttl { get; set; }
public ushort DataLength { get; set; }
}
public class DnsResponse
{
public ushort Id { get; set; }
public ushort Flags { get; set; }
public DnsRecordClass Class { get; set; }
public List<ResourceRecord> Answers { get; set; }
public long StartTime { get; set; }
public string Resolver { get; set; }
public string DnsId { get; set; }
public List<DnsQuestion> Questions { get; set; }
public List<ResourceRecord> Authorities { get; set; }
public List<ResourceRecord> Additionals { get; set; }
}
public enum DnsRecordType : ushort
{
A = 1,
NS = 2,
CNAME = 5,
MX = 15,
TXT = 16,
AAAA = 28,
}
public enum DnsRecordClass : ushort
{
/// <summary>
/// The Internet.
/// </summary>
Internet = 1,
/// <summary>
/// The CSNET class (Obsolete - used only for examples insome obsolete RFCs).
/// </summary>
CS = 2,
/// <summary>
/// The CHAOS class.
/// </summary>
CH = 3,
/// <summary>
/// Hesiod[Dyer 87].
/// </summary>
HS = 4,
/// <summary>
/// Used in UPDATE message to signify no class.
/// </summary>
None = 254,
/// <summary>
/// Only used in QCLASS.
/// </summary>
/// <seealso cref="Question.Class"/>
ANY = 255
}
}

View File

@ -16,10 +16,7 @@ namespace EonaCat.DnsTester.Helpers
public static void GetRandomUrls(ref List<string> urlList, int totalUrls)
{
// Generate a cryptographically strong random string
byte[] randomBytes = new byte[32];
_randomNumberGenerator.GetBytes(randomBytes);
string letters = Convert.ToBase64String(randomBytes);
var letters = GetRandomLetters();
Dictionary<string, string> searchEngineUrls = new Dictionary<string, string>
{
@ -81,14 +78,27 @@ namespace EonaCat.DnsTester.Helpers
}
catch (Exception ex)
{
searchEngineUrls.Remove(searchEngine.Key);
SetStatus($"{searchEngine.Key}: {ex.Message}");
}
finally
{
letters = GetRandomLetters();
}
}
urlList = localCleanNames; // Update the reference to the list
SetStatus($"{urlList.Count} Random URL's found");
}
private static string GetRandomLetters()
{
// Generate a cryptographically strong random string
byte[] randomBytes = new byte[32];
_randomNumberGenerator.GetBytes(randomBytes);
return Convert.ToBase64String(randomBytes);
}
private static void SetStatus(string text)
{
Log?.Invoke(null, text);

View File

@ -6,7 +6,7 @@
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
@ -29,360 +29,353 @@
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.ResultView = new System.Windows.Forms.ListView();
this.WebName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.DNS1IP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.DNS1Timing = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.DNS2IP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.DNS2Timing = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.RunTest = new System.Windows.Forms.Button();
this.lblDns1 = new System.Windows.Forms.Label();
this.lblDns2 = new System.Windows.Forms.Label();
this.dnsList1 = new System.Windows.Forms.ComboBox();
this.dnsList2 = new System.Windows.Forms.ComboBox();
this.UseCustomServers = new System.Windows.Forms.CheckBox();
this.lblCustom1 = new System.Windows.Forms.Label();
this.lblCustom2 = new System.Windows.Forms.Label();
this.CustomDns1 = new System.Windows.Forms.TextBox();
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.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtResolveIP = new System.Windows.Forms.TextBox();
this.txtResolveHost = new System.Windows.Forms.TextBox();
this.btnResolveIP = new System.Windows.Forms.Button();
this.btnResolveHost = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
ResultView = new System.Windows.Forms.ListView();
WebName = new System.Windows.Forms.ColumnHeader();
DNS1IP = new System.Windows.Forms.ColumnHeader();
DNS1Timing = new System.Windows.Forms.ColumnHeader();
DNS2IP = new System.Windows.Forms.ColumnHeader();
DNS2Timing = new System.Windows.Forms.ColumnHeader();
RunTest = new System.Windows.Forms.Button();
lblDns1 = new System.Windows.Forms.Label();
lblDns2 = new System.Windows.Forms.Label();
dnsList1 = new System.Windows.Forms.ComboBox();
dnsList2 = new System.Windows.Forms.ComboBox();
UseCustomServers = new System.Windows.Forms.CheckBox();
lblCustom1 = new System.Windows.Forms.Label();
lblCustom2 = new System.Windows.Forms.Label();
CustomDns1 = new System.Windows.Forms.TextBox();
CustomDns2 = new System.Windows.Forms.TextBox();
lslStatus = new System.Windows.Forms.Label();
StatusBox = new System.Windows.Forms.ListBox();
chkDns1 = new System.Windows.Forms.CheckBox();
chkDns2 = new System.Windows.Forms.CheckBox();
label1 = new System.Windows.Forms.Label();
label2 = new System.Windows.Forms.Label();
txtResolveIP = new System.Windows.Forms.TextBox();
txtResolveHost = new System.Windows.Forms.TextBox();
btnResolveIP = new System.Windows.Forms.Button();
btnResolveHost = new System.Windows.Forms.Button();
label3 = new System.Windows.Forms.Label();
numericUpDown1 = new System.Windows.Forms.NumericUpDown();
comboBox1 = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit();
SuspendLayout();
//
// ResultView
//
this.ResultView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.WebName,
this.DNS1IP,
this.DNS1Timing,
this.DNS2IP,
this.DNS2Timing});
this.ResultView.GridLines = true;
this.ResultView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.ResultView.HideSelection = false;
this.ResultView.Location = new System.Drawing.Point(155, 379);
this.ResultView.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
this.ResultView.MultiSelect = false;
this.ResultView.Name = "ResultView";
this.ResultView.Size = new System.Drawing.Size(2209, 753);
this.ResultView.TabIndex = 11;
this.ResultView.UseCompatibleStateImageBehavior = false;
this.ResultView.View = System.Windows.Forms.View.Details;
ResultView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { WebName, DNS1IP, DNS1Timing, DNS2IP, DNS2Timing });
ResultView.GridLines = true;
ResultView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
ResultView.Location = new System.Drawing.Point(155, 469);
ResultView.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
ResultView.MultiSelect = false;
ResultView.Name = "ResultView";
ResultView.Size = new System.Drawing.Size(2209, 663);
ResultView.TabIndex = 11;
ResultView.UseCompatibleStateImageBehavior = false;
ResultView.View = System.Windows.Forms.View.Details;
//
// WebName
//
this.WebName.Text = "URL";
this.WebName.Width = 160;
WebName.Text = "URL";
WebName.Width = 160;
//
// DNS1IP
//
this.DNS1IP.Text = "IP Address from DNS 1";
this.DNS1IP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.DNS1IP.Width = 140;
DNS1IP.Text = "IP Address from DNS 1";
DNS1IP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS1IP.Width = 140;
//
// DNS1Timing
//
this.DNS1Timing.Text = "DNS 1 Timing";
this.DNS1Timing.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.DNS1Timing.Width = 120;
DNS1Timing.Text = "DNS 1 Timing";
DNS1Timing.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS1Timing.Width = 120;
//
// DNS2IP
//
this.DNS2IP.Text = "IP Address from DNS 2";
this.DNS2IP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.DNS2IP.Width = 140;
DNS2IP.Text = "IP Address from DNS 2";
DNS2IP.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS2IP.Width = 140;
//
// DNS2Timing
//
this.DNS2Timing.Text = "DNS 2 Timing";
this.DNS2Timing.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.DNS2Timing.Width = 120;
DNS2Timing.Text = "DNS 2 Timing";
DNS2Timing.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
DNS2Timing.Width = 120;
//
// RunTest
//
this.RunTest.Location = new System.Drawing.Point(1131, 1152);
this.RunTest.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
this.RunTest.Name = "RunTest";
this.RunTest.Size = new System.Drawing.Size(200, 55);
this.RunTest.TabIndex = 12;
this.RunTest.Text = "Run Test";
this.RunTest.Click += new System.EventHandler(this.RunTest_Click);
RunTest.Location = new System.Drawing.Point(1131, 1152);
RunTest.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
RunTest.Name = "RunTest";
RunTest.Size = new System.Drawing.Size(200, 55);
RunTest.TabIndex = 12;
RunTest.Text = "Run Test";
RunTest.Click += RunTest_Click;
//
// lblDns1
//
this.lblDns1.AutoSize = true;
this.lblDns1.Location = new System.Drawing.Point(155, 167);
this.lblDns1.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
this.lblDns1.Name = "lblDns1";
this.lblDns1.Size = new System.Drawing.Size(95, 32);
this.lblDns1.TabIndex = 13;
this.lblDns1.Text = "Dns 1:";
lblDns1.AutoSize = true;
lblDns1.Location = new System.Drawing.Point(155, 167);
lblDns1.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
lblDns1.Name = "lblDns1";
lblDns1.Size = new System.Drawing.Size(100, 41);
lblDns1.TabIndex = 13;
lblDns1.Text = "Dns 1:";
//
// lblDns2
//
this.lblDns2.AutoSize = true;
this.lblDns2.Location = new System.Drawing.Point(1096, 167);
this.lblDns2.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
this.lblDns2.Name = "lblDns2";
this.lblDns2.Size = new System.Drawing.Size(95, 32);
this.lblDns2.TabIndex = 14;
this.lblDns2.Text = "Dns 2:";
lblDns2.AutoSize = true;
lblDns2.Location = new System.Drawing.Point(1174, 173);
lblDns2.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
lblDns2.Name = "lblDns2";
lblDns2.Size = new System.Drawing.Size(100, 41);
lblDns2.TabIndex = 14;
lblDns2.Text = "Dns 2:";
//
// dnsList1
//
this.dnsList1.FormattingEnabled = true;
this.dnsList1.ItemHeight = 31;
this.dnsList1.Location = new System.Drawing.Point(277, 155);
this.dnsList1.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
this.dnsList1.Name = "dnsList1";
this.dnsList1.Size = new System.Drawing.Size(756, 39);
this.dnsList1.TabIndex = 15;
dnsList1.FormattingEnabled = true;
dnsList1.ItemHeight = 41;
dnsList1.Location = new System.Drawing.Point(277, 155);
dnsList1.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
dnsList1.Name = "dnsList1";
dnsList1.Size = new System.Drawing.Size(756, 49);
dnsList1.TabIndex = 15;
//
// dnsList2
//
this.dnsList2.FormattingEnabled = true;
this.dnsList2.ItemHeight = 31;
this.dnsList2.Location = new System.Drawing.Point(1229, 155);
this.dnsList2.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
this.dnsList2.Name = "dnsList2";
this.dnsList2.Size = new System.Drawing.Size(788, 39);
this.dnsList2.TabIndex = 16;
dnsList2.FormattingEnabled = true;
dnsList2.ItemHeight = 41;
dnsList2.Location = new System.Drawing.Point(1307, 161);
dnsList2.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
dnsList2.Name = "dnsList2";
dnsList2.Size = new System.Drawing.Size(788, 49);
dnsList2.TabIndex = 16;
//
// UseCustomServers
//
this.UseCustomServers.AutoSize = true;
this.UseCustomServers.Location = new System.Drawing.Point(2091, 167);
this.UseCustomServers.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
this.UseCustomServers.Name = "UseCustomServers";
this.UseCustomServers.Size = new System.Drawing.Size(253, 36);
this.UseCustomServers.TabIndex = 17;
this.UseCustomServers.Text = "Custom Servers";
this.UseCustomServers.UseVisualStyleBackColor = true;
this.UseCustomServers.CheckedChanged += new System.EventHandler(this.UseCustomServers_CheckedChanged);
UseCustomServers.AutoSize = true;
UseCustomServers.Location = new System.Drawing.Point(2169, 173);
UseCustomServers.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
UseCustomServers.Name = "UseCustomServers";
UseCustomServers.Size = new System.Drawing.Size(262, 45);
UseCustomServers.TabIndex = 17;
UseCustomServers.Text = "Custom Servers";
UseCustomServers.UseVisualStyleBackColor = true;
UseCustomServers.CheckedChanged += UseCustomServers_CheckedChanged;
//
// lblCustom1
//
this.lblCustom1.AutoSize = true;
this.lblCustom1.Location = new System.Drawing.Point(155, 293);
this.lblCustom1.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
this.lblCustom1.Name = "lblCustom1";
this.lblCustom1.Size = new System.Drawing.Size(206, 32);
this.lblCustom1.TabIndex = 18;
this.lblCustom1.Text = "Custom Dns 1: ";
this.lblCustom1.Visible = false;
lblCustom1.AutoSize = true;
lblCustom1.Location = new System.Drawing.Point(155, 328);
lblCustom1.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
lblCustom1.Name = "lblCustom1";
lblCustom1.Size = new System.Drawing.Size(219, 41);
lblCustom1.TabIndex = 18;
lblCustom1.Text = "Custom Dns 1: ";
lblCustom1.Visible = false;
//
// lblCustom2
//
this.lblCustom2.AutoSize = true;
this.lblCustom2.Location = new System.Drawing.Point(1096, 293);
this.lblCustom2.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
this.lblCustom2.Name = "lblCustom2";
this.lblCustom2.Size = new System.Drawing.Size(206, 32);
this.lblCustom2.TabIndex = 19;
this.lblCustom2.Text = "Custom Dns 2: ";
this.lblCustom2.Visible = false;
lblCustom2.AutoSize = true;
lblCustom2.Location = new System.Drawing.Point(1174, 334);
lblCustom2.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
lblCustom2.Name = "lblCustom2";
lblCustom2.Size = new System.Drawing.Size(219, 41);
lblCustom2.TabIndex = 19;
lblCustom2.Text = "Custom Dns 2: ";
lblCustom2.Visible = false;
//
// CustomDns1
//
this.CustomDns1.BackColor = System.Drawing.Color.White;
this.CustomDns1.Enabled = false;
this.CustomDns1.Location = new System.Drawing.Point(408, 289);
this.CustomDns1.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
this.CustomDns1.Name = "CustomDns1";
this.CustomDns1.Size = new System.Drawing.Size(625, 38);
this.CustomDns1.TabIndex = 20;
this.CustomDns1.Visible = false;
CustomDns1.BackColor = System.Drawing.Color.White;
CustomDns1.Enabled = false;
CustomDns1.Location = new System.Drawing.Point(408, 324);
CustomDns1.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
CustomDns1.Name = "CustomDns1";
CustomDns1.Size = new System.Drawing.Size(625, 47);
CustomDns1.TabIndex = 20;
CustomDns1.Visible = false;
//
// CustomDns2
//
this.CustomDns2.Enabled = false;
this.CustomDns2.Location = new System.Drawing.Point(1349, 289);
this.CustomDns2.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
this.CustomDns2.Name = "CustomDns2";
this.CustomDns2.Size = new System.Drawing.Size(668, 38);
this.CustomDns2.TabIndex = 21;
this.CustomDns2.Visible = false;
CustomDns2.Enabled = false;
CustomDns2.Location = new System.Drawing.Point(1427, 330);
CustomDns2.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
CustomDns2.Name = "CustomDns2";
CustomDns2.Size = new System.Drawing.Size(668, 47);
CustomDns2.TabIndex = 21;
CustomDns2.Visible = false;
//
// lslStatus
//
this.lslStatus.AutoSize = true;
this.lslStatus.Location = new System.Drawing.Point(155, 1219);
this.lslStatus.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
this.lslStatus.Name = "lslStatus";
this.lslStatus.Size = new System.Drawing.Size(103, 32);
this.lslStatus.TabIndex = 22;
this.lslStatus.Text = "Status:";
lslStatus.AutoSize = true;
lslStatus.Location = new System.Drawing.Point(155, 1219);
lslStatus.Margin = new System.Windows.Forms.Padding(8, 0, 8, 0);
lslStatus.Name = "lslStatus";
lslStatus.Size = new System.Drawing.Size(105, 41);
lslStatus.TabIndex = 22;
lslStatus.Text = "Status:";
//
// StatusBox
//
this.StatusBox.FormattingEnabled = true;
this.StatusBox.HorizontalScrollbar = true;
this.StatusBox.ItemHeight = 31;
this.StatusBox.Location = new System.Drawing.Point(155, 1271);
this.StatusBox.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
this.StatusBox.Name = "StatusBox";
this.StatusBox.Size = new System.Drawing.Size(2209, 376);
this.StatusBox.TabIndex = 23;
StatusBox.FormattingEnabled = true;
StatusBox.HorizontalScrollbar = true;
StatusBox.ItemHeight = 41;
StatusBox.Location = new System.Drawing.Point(155, 1271);
StatusBox.Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
StatusBox.Name = "StatusBox";
StatusBox.Size = new System.Drawing.Size(2209, 373);
StatusBox.TabIndex = 23;
//
// 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, 220);
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;
chkDns1.AutoSize = true;
chkDns1.Checked = true;
chkDns1.CheckState = System.Windows.Forms.CheckState.Checked;
chkDns1.Location = new System.Drawing.Point(277, 235);
chkDns1.Name = "chkDns1";
chkDns1.Size = new System.Drawing.Size(251, 45);
chkDns1.TabIndex = 24;
chkDns1.Text = "Test dns server";
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, 220);
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;
chkDns2.AutoSize = true;
chkDns2.Checked = true;
chkDns2.CheckState = System.Windows.Forms.CheckState.Checked;
chkDns2.Location = new System.Drawing.Point(1307, 241);
chkDns2.Name = "chkDns2";
chkDns2.Size = new System.Drawing.Size(251, 45);
chkDns2.TabIndex = 25;
chkDns2.Text = "Test dns server";
chkDns2.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(155, 27);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(263, 32);
this.label1.TabIndex = 26;
this.label1.Text = "Resolve ip address:";
label1.AutoSize = true;
label1.Location = new System.Drawing.Point(155, 27);
label1.Name = "label1";
label1.Size = new System.Drawing.Size(270, 41);
label1.TabIndex = 26;
label1.Text = "Resolve ip address:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(1102, 27);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(257, 32);
this.label2.TabIndex = 27;
this.label2.Text = "Resolve hostname:";
label2.AutoSize = true;
label2.Location = new System.Drawing.Point(1180, 33);
label2.Name = "label2";
label2.Size = new System.Drawing.Size(266, 41);
label2.TabIndex = 27;
label2.Text = "Resolve hostname:";
//
// txtResolveIP
//
this.txtResolveIP.Location = new System.Drawing.Point(425, 21);
this.txtResolveIP.Name = "txtResolveIP";
this.txtResolveIP.Size = new System.Drawing.Size(608, 38);
this.txtResolveIP.TabIndex = 28;
txtResolveIP.Location = new System.Drawing.Point(425, 21);
txtResolveIP.Name = "txtResolveIP";
txtResolveIP.Size = new System.Drawing.Size(608, 47);
txtResolveIP.TabIndex = 28;
//
// txtResolveHost
//
this.txtResolveHost.Location = new System.Drawing.Point(1365, 21);
this.txtResolveHost.Name = "txtResolveHost";
this.txtResolveHost.Size = new System.Drawing.Size(651, 38);
this.txtResolveHost.TabIndex = 29;
txtResolveHost.Location = new System.Drawing.Point(1443, 27);
txtResolveHost.Name = "txtResolveHost";
txtResolveHost.Size = new System.Drawing.Size(651, 47);
txtResolveHost.TabIndex = 29;
//
// btnResolveIP
//
this.btnResolveIP.Location = new System.Drawing.Point(425, 75);
this.btnResolveIP.Name = "btnResolveIP";
this.btnResolveIP.Size = new System.Drawing.Size(195, 70);
this.btnResolveIP.TabIndex = 30;
this.btnResolveIP.Text = "Resolve";
this.btnResolveIP.UseVisualStyleBackColor = true;
this.btnResolveIP.Click += new System.EventHandler(this.btnResolveIP_Click);
btnResolveIP.Location = new System.Drawing.Point(425, 75);
btnResolveIP.Name = "btnResolveIP";
btnResolveIP.Size = new System.Drawing.Size(205, 51);
btnResolveIP.TabIndex = 30;
btnResolveIP.Text = "Resolve";
btnResolveIP.UseVisualStyleBackColor = true;
btnResolveIP.Click += btnResolveIP_Click;
//
// btnResolveHost
//
this.btnResolveHost.Location = new System.Drawing.Point(1366, 75);
this.btnResolveHost.Name = "btnResolveHost";
this.btnResolveHost.Size = new System.Drawing.Size(221, 70);
this.btnResolveHost.TabIndex = 31;
this.btnResolveHost.Text = "Resolve";
this.btnResolveHost.UseVisualStyleBackColor = true;
this.btnResolveHost.Click += new System.EventHandler(this.btnResolveHost_Click);
btnResolveHost.Location = new System.Drawing.Point(1443, 81);
btnResolveHost.Name = "btnResolveHost";
btnResolveHost.Size = new System.Drawing.Size(167, 45);
btnResolveHost.TabIndex = 31;
btnResolveHost.Text = "Resolve";
btnResolveHost.UseVisualStyleBackColor = true;
btnResolveHost.Click += btnResolveHost_Click;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(675, 223);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(201, 32);
this.label3.TabIndex = 32;
this.label3.Text = "Total domains:";
label3.AutoSize = true;
label3.Location = new System.Drawing.Point(675, 238);
label3.Name = "label3";
label3.Size = new System.Drawing.Size(210, 41);
label3.TabIndex = 32;
label3.Text = "Total domains:";
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(913, 223);
this.numericUpDown1.Maximum = new decimal(new int[] {
1000000000,
0,
0,
0});
this.numericUpDown1.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(120, 38);
this.numericUpDown1.TabIndex = 33;
this.numericUpDown1.Value = new decimal(new int[] {
20,
0,
0,
0});
numericUpDown1.Location = new System.Drawing.Point(913, 238);
numericUpDown1.Maximum = new decimal(new int[] { 1000000000, 0, 0, 0 });
numericUpDown1.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
numericUpDown1.Name = "numericUpDown1";
numericUpDown1.Size = new System.Drawing.Size(120, 47);
numericUpDown1.TabIndex = 33;
numericUpDown1.Value = new decimal(new int[] { 20, 0, 0, 0 });
//
// comboBox1
//
comboBox1.FormattingEnabled = true;
comboBox1.Items.AddRange(new object[] { "A", "NS", "CNAME", "MX", "TXT" });
comboBox1.Location = new System.Drawing.Point(2129, 251);
comboBox1.Name = "comboBox1";
comboBox1.Size = new System.Drawing.Size(302, 49);
comboBox1.TabIndex = 34;
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
//
// 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.numericUpDown1);
this.Controls.Add(this.label3);
this.Controls.Add(this.btnResolveHost);
this.Controls.Add(this.btnResolveIP);
this.Controls.Add(this.txtResolveHost);
this.Controls.Add(this.txtResolveIP);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
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);
this.Controls.Add(this.CustomDns1);
this.Controls.Add(this.lblCustom2);
this.Controls.Add(this.lblCustom1);
this.Controls.Add(this.UseCustomServers);
this.Controls.Add(this.dnsList2);
this.Controls.Add(this.dnsList1);
this.Controls.Add(this.lblDns2);
this.Controls.Add(this.lblDns1);
this.Controls.Add(this.RunTest);
this.Controls.Add(this.ResultView);
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 = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "EonaCat.DnsTester";
this.Load += new System.EventHandler(this.TesterUI_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
AutoScaleDimensions = new System.Drawing.SizeF(240F, 240F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
AutoSize = true;
AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
ClientSize = new System.Drawing.Size(2517, 1693);
Controls.Add(comboBox1);
Controls.Add(numericUpDown1);
Controls.Add(label3);
Controls.Add(btnResolveHost);
Controls.Add(btnResolveIP);
Controls.Add(txtResolveHost);
Controls.Add(txtResolveIP);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(chkDns2);
Controls.Add(chkDns1);
Controls.Add(StatusBox);
Controls.Add(lslStatus);
Controls.Add(CustomDns2);
Controls.Add(CustomDns1);
Controls.Add(lblCustom2);
Controls.Add(lblCustom1);
Controls.Add(UseCustomServers);
Controls.Add(dnsList2);
Controls.Add(dnsList1);
Controls.Add(lblDns2);
Controls.Add(lblDns1);
Controls.Add(RunTest);
Controls.Add(ResultView);
Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon");
Margin = new System.Windows.Forms.Padding(8, 7, 8, 7);
MaximizeBox = false;
Name = "MainForm";
StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
Text = "EonaCat.DnsTester";
Load += TesterUI_Load;
((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
@ -415,6 +408,7 @@
private System.Windows.Forms.Button btnResolveHost;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.ComboBox comboBox1;
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.DirectoryServices.ActiveDirectory;
using System.IO;
using System.Linq;
using System.Net;
@ -19,6 +20,7 @@ namespace EonaCat.DnsTester
{
private bool useCustomDnsServers;
private string _dnsServer1, _dnsServer2;
private DnsRecordType _recordType;
private int _dnsTotalChecked;
public bool IsRunning { get; private set; }
@ -28,10 +30,17 @@ namespace EonaCat.DnsTester
InitializeComponent();
}
private void RunTest_Click(object sender, EventArgs e)
private async void RunTest_Click(object sender, EventArgs e)
{
List<string> urls = new List<string>();
SetupUrls(urls);
SetupView();
await Task.Run(() =>
{
UrlHelper.GetRandomUrls(ref urls, (int)numericUpDown1.Value);
});
AddUrlToView(urls);
if (IsRunning)
{
@ -39,11 +48,11 @@ namespace EonaCat.DnsTester
}
IsRunning = true;
Process(urls.ToArray(), _dnsServer1, _dnsServer2);
Process(_recordType, urls.ToArray(), _dnsServer1, _dnsServer2);
IsRunning = false;
}
private void SetupUrls(List<string> urls)
private void SetupView()
{
if (useCustomDnsServers)
{
@ -81,9 +90,8 @@ namespace EonaCat.DnsTester
ResultView.Update();
Application.DoEvents();
UrlHelper.Log -= UrlHelper_Log;
UrlHelper.Log += UrlHelper_Log;
UrlHelper.GetRandomUrls(ref urls, (int)numericUpDown1.Value);
AddUrlToView(urls);
}
private void UrlHelper_Log(object sender, string e)
@ -178,89 +186,132 @@ namespace EonaCat.DnsTester
}
private void Process(string[] urls, string dnsAddress1, string dnsAddress2)
private async Task Process(DnsRecordType recordType, string[] urls, string dnsAddress1, string dnsAddress2)
{
int i;
int urlsTotal = urls.Length;
const int ipPort = 53;
const string transactionId1 = "Q1";
const string transactionId2 = "Q2";
const string typeString = "\u0001" + "\u0000" + "\u0000" + "\u0001" + "\u0000" + "\u0000" + "\u0000" + "\u0000" + "\u0000" + "\u0000";
const string trailerString = "\u0000" + "\u0000" + "\u0001" + "\u0000" + "\u0001";
const int dnsReceiveTimeout = 5000;
string startOfUrl = string.Empty;
string domain = string.Empty;
byte[] bytesSend = new byte[256];
Socket dnsSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
dnsSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, dnsReceiveTimeout);
SetupDnsServers(dnsAddress1, dnsAddress2, ipPort, out var dnsEndpoint1, out var dnsEndpoint2);
// Start the clock
var startTime = DateTime.Now.Ticks;
for (i = 0; i < urlsTotal; i++)
if (recordType == 0)
{
var currentUrl = urls[i];
startOfUrl = currentUrl.Substring(0, currentUrl.IndexOf("."));
domain = currentUrl.Substring(currentUrl.IndexOf(".") + 1,
currentUrl.Length - currentUrl.IndexOf(".") - 1);
var dnsQuery = typeString + (char)startOfUrl.Length + startOfUrl + (char)domain.Length + domain +
trailerString;
string queryString;
if (chkDns1.Checked)
{
queryString = transactionId1 + dnsQuery;
bytesSend = Encoding.ASCII.GetBytes(queryString);
if (dnsEndpoint1 != null)
dnsSocket.SendTo(bytesSend, bytesSend.Length, SocketFlags.None, dnsEndpoint1);
}
if (!chkDns2.Checked) continue;
queryString = transactionId2 + dnsQuery;
bytesSend = Encoding.ASCII.GetBytes(queryString);
if (dnsEndpoint2 != null) dnsSocket.SendTo(bytesSend, bytesSend.Length, SocketFlags.None, dnsEndpoint2);
recordType = DnsRecordType.A;
}
int 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++)
{
var currentUrl = urls[i];
await ExecuteDns1(recordType, dnsAddress1, currentUrl, dnsId1, i);
if (!chkDns2.Checked) continue;
await ExecuteDns2(recordType, dnsAddress2, currentUrl, dnsId2, i);
await Task.Delay(100);
}
}
private async Task ExecuteDns2(DnsRecordType recordType, string dnsAddress2, string currentUrl, string dnsId2,
int i)
{
try
{
DnsHelper.Log += DnsHelper_Log;
DnsHelper.ProcessDns(startOfUrl, domain, urlsTotal, dnsSocket, bytesSend, startTime, _dnsTotalChecked, ResultView);
DnsResponse response2 = null;
byte[] queryBytes2 = DnsHelper.CreateDnsQueryPacket(currentUrl, recordType);
response2 = await DnsHelper.SendDnsQueryPacket(dnsId2, dnsAddress2, 53, queryBytes2);
ProcessResponse(response2);
}
catch (SocketException socketException)
{
SetStatus(
Convert.ToString(socketException).IndexOf("time", StringComparison.Ordinal) > 0
? $"Timeout - No response received for {Convert.ToString(dnsReceiveTimeout / 1000)} seconds"
? $"DNS1 Timeout - No response received for {Convert.ToString(DnsHelper.DnsReceiveTimeout / 1000)} seconds"
: Convert.ToString(socketException));
}
finally
catch (Exception exception)
{
// close the socket
dnsSocket.Close();
SetStatus(exception.Message);
i--;
}
}
private void DnsHelper_Log(object sender, string e)
private async Task ExecuteDns1(DnsRecordType recordType, string dnsAddress1, string currentUrl, string dnsId1,
int i)
{
if (chkDns1.Checked)
{
try
{
DnsResponse response1 = null;
byte[] queryBytes1 = DnsHelper.CreateDnsQueryPacket(currentUrl, recordType);
response1 = await DnsHelper.SendDnsQueryPacket(dnsId1, dnsAddress1, 53, queryBytes1);
ProcessResponse(response1);
}
catch (SocketException socketException)
{
SetStatus(
Convert.ToString(socketException).IndexOf("time", StringComparison.Ordinal) > 0
? $"DNS1 Timeout - No response received for {Convert.ToString(DnsHelper.DnsReceiveTimeout / 1000)} seconds"
: Convert.ToString(socketException));
}
catch (Exception exception)
{
SetStatus(exception.Message);
i--;
}
}
}
private void DnsHelper_OnLog(object sender, string e)
{
SetStatus(e);
}
private void SetupDnsServers(string dnsAddress1, string dnsAddress2, int ipPort, out IPEndPoint dnsEndpoint1,
out IPEndPoint dnsEndpoint2)
private void ProcessResponse(DnsResponse dnsResponse)
{
dnsEndpoint1 = null;
if (chkDns1.Checked && !string.IsNullOrWhiteSpace(dnsAddress1))
if (dnsResponse == null || dnsResponse.Answers == null || !dnsResponse.Answers.Any())
{
dnsEndpoint1 = new IPEndPoint(IPAddress.Parse(dnsAddress1), ipPort);
return;
}
dnsEndpoint2 = null;
if (chkDns2.Checked && !string.IsNullOrWhiteSpace(dnsAddress2))
// Retrieve stopTime
var stopTime = DateTime.Now.Ticks;
var deltaTime = Convert.ToString((double)(stopTime - dnsResponse.StartTime) / 10000000);
SetStatus($"ResourceRecord: Name: {dnsResponse.Answers.FirstOrDefault().Name} : Type : {dnsResponse.Answers.FirstOrDefault().Type} : Data : {dnsResponse.Answers.FirstOrDefault().Data}");
for (int i = 0; i < ResultView.Items.Count; i++)
{
dnsEndpoint2 = new IPEndPoint(IPAddress.Parse(dnsAddress2), ipPort);
if (ResultView.Items[i].Text != $"{dnsResponse.Answers.FirstOrDefault().Name.TrimEnd('.')}") continue;
string sDeltaTime;
switch (dnsResponse.DnsId)
{
case "Dns1":
ResultView.Items[i].SubItems[1].Text = Convert.ToString(dnsResponse.Answers.FirstOrDefault().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(dnsResponse.Answers.FirstOrDefault().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;
}
}
}
@ -323,15 +374,27 @@ namespace EonaCat.DnsTester
private void SetStatus(string text)
{
StatusBox.Items.Add($"{DateTime.Now} {text}");
StatusBox.TopIndex = StatusBox.Items.Count - 1;
if (StatusBox.Items.Count > STATUS_BAR_SIZE)
StatusBox.Invoke(() =>
{
StatusBox.Items.RemoveAt(0);
}
StatusBox.Update();
StatusBox.Items.Add($"{DateTime.Now} {text}");
StatusBox.TopIndex = StatusBox.Items.Count - 1;
if (StatusBox.Items.Count > STATUS_BAR_SIZE)
{
StatusBox.Items.RemoveAt(0);
}
StatusBox.Update();
});
}
const int STATUS_BAR_SIZE = 5000;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (Enum.TryParse(comboBox1.SelectedItem.ToString().ToUpper(), out DnsRecordType queryType))
{
_recordType = queryType;
}
}
}
}

View File

@ -1,64 +1,4 @@
<?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.
-->
<root>
<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

@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EonaCat.EonaCat.DnsTester")]
[assembly: AssemblyCopyright("Copyright © EonaCat (Jeroen Saey) 2027")]
[assembly: AssemblyCopyright("Copyright © EonaCat (Jeroen Saey) 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

View File

@ -8,11 +8,11 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace EonaCat.EonaCat.DnsTester.Properties {
namespace EonaCat.DnsTester.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@ -22,5 +22,17 @@ namespace EonaCat.EonaCat.DnsTester.Properties {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string EonaCat {
get {
return ((string)(this["EonaCat"]));
}
set {
this["EonaCat"] = value;
}
}
}
}

View File

@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="EonaCat.DnsTester.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="EonaCat" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View File

@ -1,25 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<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>
<!--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-->
<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-->
<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>
<!--AdGuard DNS-->
<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>
<!-- 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-->
<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-->
<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>
</Servers>