MichaCo / DnsClient.NET

DnsClient.NET is a simple yet very powerful and high performant open source library for the .NET Framework to do DNS lookups
https://dnsclient.michaco.net
Apache License 2.0
762 stars 136 forks source link

HasError=false / no error message when hostname (not FQDN) has no ip address #184

Closed BornToBeRoot closed 1 year ago

BornToBeRoot commented 1 year ago

Hi @MichaCo,

if i try to resolve a hostname (not an FQDN) that doesn't exists, the HasError and ErrorMessage ist not set.

In this case the ip address is null...

Is this a bug?

Sample code to debug:

using DnsClient;

var client = new LookupClient();

foreach (var query in new List<string>() { "borntoberoot", "x.borntoberoot.net", "borntoberoot.net" })
{
    var result = client.Query(query, QueryType.A);

    Console.WriteLine("Query A: " + query);
    Console.WriteLine("Has error: " + result.HasError);
    Console.WriteLine("Error msg:" + result.ErrorMessage);
    Console.WriteLine("IP: " + result.Answers.ARecords().FirstOrDefault()?.Address);
    Console.WriteLine("");
}
Console.ReadLine();

image

MichaCo commented 1 year ago

Hi, No, that's not a bug. The DNS error code is just what the server returns in its response. The client isn't doing any validation of the results here.

In your case it seems your server returns something, maybe not an A record, but some response I guess. If you use any public DNS server, e.g dig @8.8.8.8 borntoberoot, you'll get Non-Existing Domain because that query isn't a valid domain name.

BornToBeRoot commented 1 year ago

@MichaCo Thanks for the feedback. You are right. I get the error from 1.1.1.1 and my pihole. It seems like Ubiquiti does not implement DNS correctly...