我需要像在 nslookup 中那样使用特定的 DNS 服务器解析主机名
C:\>nslookup hotname 192.100.10.10
Server: UnKnown
Address: 192.100.10.10
Name: hostname.host
Address: 192.100.10.14
当然,作为返回,我不仅想要地址,我还想要 Server
、Address
、Name
和 地址
我查看了 System.Net.Dns
类,但它只提供了已解析的 IP 地址,并且不允许我选择我选择的 DNS 服务器
如果有人以前做过这件事,你可以帮助我。
编辑:
为 C# 找到一个:http://www.simpledns.com/dns-client-lib.aspx
这是我的代码片段,仅供娱乐
//Buy him Cookies and Strippers
using JHSoftware;
最佳答案
我仍然没有 C++ 的答案,但这是 C# 的答案
var Options = new JHSoftware.DnsClient.RequestOptions();
Options.DnsServers = new System.Net.IPAddress[] {
System.Net.IPAddress.Parse("1.1.1.1"),
System.Net.IPAddress.Parse("2.2.2.2") };
var IPs = JHSoftware.DnsClient.LookupHost("www.simpledns.com",
JHSoftware.DnsClient.IPVersion.IPv4,
Options);
foreach(var IP in IPs)
{
Console.WriteLine(IP.ToString());
}
上面使用的是JHSoftware.dll,代码是从那里复制来帮助别人的,链接如下:
关于c# - 用于 C# 和 C++ 的 nslookup 以使用特定服务器解析主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2671498/