用于 C# 和 C++ 的 nslookup使用特定服务器解析主机

发布于 2024-08-29 10:39:30 字数 715 浏览 1 评论 0原文

我需要使用特定的 DNS 服务器解析主机名,就像在 nslookup 中一样

C:\>nslookup hotname 192.100.10.10
Server:  UnKnown
Address:  192.100.10.10

Name:    hostname.host
Address:  192.100.10.14

,但当然,作为回报,我不仅仅想要地址,我想要 ServerAddress 的所有值code>、NameAddress

我已经查看了 System.Net.Dns 类,但它只提供了解析的 IP 地址,而没有提供不要让我选择我选择的 DNS 服务器

如果有人以前这样做过并且你可以帮助我。

编辑:

找到一个 C# 版本:http://www. simpledns.com/dns-client-lib.aspx

这是我的代码片段,仅供娱乐

//Buy him Cookies and Strippers
using JHSoftware;

I need to resolve a hostname using a specific DNS server like you would in nslookup

C:\>nslookup hotname 192.100.10.10
Server:  UnKnown
Address:  192.100.10.10

Name:    hostname.host
Address:  192.100.10.14

But of course in return I don't just want the address I want all the values for Server, Address, Name and Address

I have looked at the System.Net.Dns Class but that only gives me the Resolved IP Address and doesn't let me select the DNS Server of my choosing

If any one has done this before and you can help me with this.

Edit:

Found One for C# : http://www.simpledns.com/dns-client-lib.aspx

Here is a snippet of my code just for some entertainment

//Buy him Cookies and Strippers
using JHSoftware;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩余の解释 2024-09-05 10:39:30

我仍然没有 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,代码是从那里复制的以帮助其他人,链接 simpledns.com/dns-client-lib.aspx" rel="nofollow noreferrer">http://www.simpledns.com/dns-client-lib.aspx

I still dont have an answer for C++ but here is the one for 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());
}

The above is using JHSoftware.dll and the code is copied from there to help others, the link is as below:

http://www.simpledns.com/dns-client-lib.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文