diff --git a/Test.sln b/Test.sln new file mode 100644 index 0000000..9b38e94 --- /dev/null +++ b/Test.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31112.23 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{A60DC222-7F65-4535-A71C-EF7EE6263E08}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A60DC222-7F65-4535-A71C-EF7EE6263E08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A60DC222-7F65-4535-A71C-EF7EE6263E08}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A60DC222-7F65-4535-A71C-EF7EE6263E08}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A60DC222-7F65-4535-A71C-EF7EE6263E08}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E3DD4713-8F53-44FB-9487-E544D1283CCE} + EndGlobalSection +EndGlobal diff --git a/Test/App.config b/Test/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Test/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test/Program.cs b/Test/Program.cs new file mode 100644 index 0000000..dc9405a --- /dev/null +++ b/Test/Program.cs @@ -0,0 +1,104 @@ +/** + * DNS Test Tool + * + * Copyright (C) 2021 Kema All Rights Reserved. + * + * + * How it work? + * change content size and replace bytes. + * last period to '02', else '04' + * * I don't know the details either + * + * Reference + * https://www.atmarkit.co.jp/ait/articles/1601/29/news014_2.html + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Net; +using System.Net.Sockets; + +namespace Test +{ + class Program + { + static void Main(string[] args) + { + int fs = Environment.TickCount; + byte[] header = new byte[12]; + header[0] = 00; // ID + header[1] = 00; + header[2] = 01; // Query + header[3] = 00; + header[4] = 00; // QDCount + header[5] = 01; + header[6] = 00; // ANCount + header[7] = 00; + header[8] = 00; // NSCount + header[9] = 00; + header[10] = 00; // ARCount + header[11] = 00; + + byte[] content = new byte[12]; + content[0] = 03; //offset + content[1] = (byte)'w'; + content[2] = (byte)'w'; + content[3] = (byte)'w'; + content[4] = 02; //. + content[5] = (byte)'j'; + content[6] = (byte)'p'; + content[7] = 00; //offset + content[8] = 00; // A + content[9] = 01; + content[10] = 00; // IN + content[11] = 01; + + byte[] data = new byte[header.Length + content.Length]; + Array.Copy(header, 0, data, 0, header.Length); + Array.Copy(content, 0, data, header.Length, content.Length); + + IPAddress ip = IPAddress.Parse("8.8.8.8"); + IPEndPoint remote = new IPEndPoint(ip, 53); + + UdpClient client = new UdpClient(); + + int et = Environment.TickCount; + Console.WriteLine("Sending Packet."); + client.Send(data, data.Length, remote); + + IPEndPoint remoteIP = null; + byte[] buffer = client.Receive(ref remoteIP); + + int le = Environment.TickCount; + + Console.WriteLine("Elapsed {0}ms", le - fs); + Console.WriteLine("Elapsed creating data {0}ms", et - fs); + Console.WriteLine(BitConverter.ToString(data)); + + byte[] answer = new byte[buffer.Length - data.Length]; + Array.Copy(buffer, data.Length, answer, 0, answer.Length); + + Console.WriteLine(BitConverter.ToString(answer)); + + // offset + //answer[0], answer[1] + // A + //answer[2], answer[3] + // IN + //answer[4], answer[5] + + int offset = answer.Length - 4; + int i0 = answer[offset + 0]; + int i1 = answer[offset + 1]; + int i2 = answer[offset + 2]; + int i3 = answer[offset + 3]; + + Console.WriteLine("{0}.{1}.{2}.{3}", i0, i1, i2, i3); + + Console.ReadLine(); + + } + } +} diff --git a/Test/Properties/AssemblyInfo.cs b/Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..767b03d --- /dev/null +++ b/Test/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 +// 制御されます。アセンブリに関連付けられている情報を変更するには、 +// これらの属性値を変更します。 +[assembly: AssemblyTitle("Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Test")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから +// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、 +// その型の ComVisible 属性を true に設定します。 +[assembly: ComVisible(false)] + +// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります +[assembly: Guid("a60dc222-7f65-4535-a71c-ef7ee6263e08")] + +// アセンブリのバージョン情報は次の 4 つの値で構成されています: +// +// メジャー バージョン +// マイナー バージョン +// ビルド番号 +// リビジョン +// +// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます +// 既定値にすることができます: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Test/Test.csproj b/Test/Test.csproj new file mode 100644 index 0000000..1282992 --- /dev/null +++ b/Test/Test.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {A60DC222-7F65-4535-A71C-EF7EE6263E08} + Exe + Test + Test + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file