Reputation: 3013
In .NET you can make a call to
Dns.GetHostEntry(hostname)
This uses the DNS entries on your NETWORK Settings to do the DNS Look up, but I would like to specify the DNS Server 8.8.8.8
to do the look up against, without changes the DNS Settings in the NETWORK Settings.
Can this be accomplished?
Upvotes: 3
Views: 2863
Reputation: 13381
There is nothing build into .NET yet, but there are NuGet packages you can use which do an actual DNS lookup against a DNS server of your choice.
DnsClient.NET is one of those. It also has methods to create a host entry with similar syntax.
Example:
var endpoint = new IPEndPoint(NameServer.GooglePublicDns);
var lookup = new LookupClient(endpoint);
IPHostEntry hostEntry = lookup.GetHostEntry(hostOrIp);
Console.WriteLine(hostEntry.HostName);
foreach (var ip in hostEntry.AddressList)
{
Console.WriteLine(ip);
}
foreach (var alias in hostEntry.Aliases)
{
Console.WriteLine(alias);
}
Upvotes: 3