コード例 #1
0
 public async Task TestLookupWithGoogle(string domain, DnsQueryType type)
 {
     using var client = new DnsTcpClient(new NullLogger <DnsTcpClient>(), IPAddress.Parse("8.8.8.8"));
     await client.RunQuery(domain, type);
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Moerty/dnstools
        private void buttonClientSend_Click(object sender, EventArgs e)
        {
            string    errorMessage;
            IPAddress serverAddr;

            Cursor = Cursors.WaitCursor;
            buttonClientSend.Enabled = false;

            if (!ValidateServerText(textBoxClientServer.Text, out errorMessage))
            {
                errorProvider1.SetError(textBoxClientServer, errorMessage);
                return;
            }
            try
            {
                // resolve server name by System.Net.Dns
                serverAddr = System.Net.Dns.GetHostAddresses(textBoxClientServer.Text.Trim()).First();
            }
            catch (SocketException)
            {
                errorProvider1.SetError(textBoxClientServer, "Server name cannot be resolved.");
                return;
            }

            try
            {
                IDnsClient client;
                if (radioButtonClientTCP.Checked)
                {
                    client = new DnsTcpClient();
                }
                else
                {
                    client = new DnsUdpClient();
                }

                Request request = new Request(
                    (ushort)DateTime.Now.Ticks,
                    checkBoxClientRD.Checked,
                    (OPCODE)Enum.Parse(typeof(OPCODE), comboBoxClientOPCODE.SelectedValue.ToString()),
                    new Question(
                        textBoxClientQNAME.Text.Trim(),
                        (QTYPE)Enum.Parse(typeof(QTYPE), comboBoxClientQTYPE.SelectedValue.ToString()),
                        (QCLASS)Enum.Parse(typeof(QCLASS), comboBoxClientQCLASS.SelectedValue.ToString())));


                labelClientResponse.Text   = String.Empty;
                textBoxClientResponse.Text = String.Empty;

                client.Connect(serverAddr);
                client.BeginProcess(request, new AsyncCallback(OnClientResponseReceived),
                                    new ClientAsyncState {
                    Client = client, Request = request, Server = serverAddr
                });

                //try
                //{
                //  client.Connect(serverAddr);
                //  DnsClient.Response response = client.LookUp(request);
                //  labelClientResponse.Text = String.Format("{0}: {1} from [{2}] in {3}ms",
                //    (response.Header.AA ? "Authoritative Response" : "Non-Authoritative Response"),
                //    response.Header.RCODE.ToString(),
                //    serverAddr.ToString(),
                //    response.Timestamp.Subtract(request.Timestamp).TotalMilliseconds);
                //  StringBuilder result = new StringBuilder();
                //  RenderResponse(response, result);
                //  textBoxClientResponse.Text = result.ToString();
                //}
                //finally
                //{
                //  Cursor = Cursors.Default;
                //  buttonClientSend.Enabled = true;
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
 public async Task TestLookupWithCloudFlare(string domain, DnsQueryType type)
 {
     using var client = new DnsTcpClient(new NullLogger <DnsTcpClient>(), IPAddress.Parse("1.1.1.1"));
     await client.RunQuery(domain, type, type == DnsQueryType.ANY?DnsResponseCode.NotImp : DnsResponseCode.NoError);
 }