C#查找DNS是否存在于DNS服务器上(来自域控制器)

问题描述:

我想检查域控制器上是否存在DNS记录。 例如: 如果我想要检查我我有我的工作域上的DNS服务器上的主机“guest_PC”。C#查找DNS是否存在于DNS服务器上(来自域控制器)

+0

然后做一个DNS查找,什么问题和问题,你用它 – BugFinder

+0

,我需要查询特定的DNS服务器拥有。 。 –

+0

所以你没有搜索堆栈溢出然后http://*.com/questions/8227863/dns-lookup-from-custom-dns-server-in-c-sharp – BugFinder

以下示例将查询DNS数据库以获取主机www.contoso.com上的信息。

using System.Net; 
    IPHostEntry hostInfo = Dns.GetHostByName("www.contoso.com"); 
    static string IP = Dns.GetHostName(); 

请参阅https://msdn.microsoft.com/en-us/library/system.net.dns(v=vs.110).aspx了解更多信息。

+0

但我想问具体的DNS服务器.. –

+0

所以你没有搜索到这一切有你 – BugFinder

使用类似DnsClient.NEThttps://github.com/MichaCo/DnsClient.NET)的库来从您的代码/应用程序中针对任何DNS服务器运行查询。

下面是如何使用图书馆只是一个简单的例子:

// use the IP Address of your DNS server 
var endpoint = new IPEndPoint(IPAddress.Parse("1.2.3.4"), 53); 
var client = new LookupClient(endpoint); 

// then query for the host in your domain and ask for an A or AAAA record 
var result = client.Query("YouHost.yourdomain", QueryType.A); 
var ipRecord = result.Answers.ARecords().First(); 
Console.WriteLine($"IP: {ipRecord.Address}."); 

// shortcut 
var entry = client.GetHostEntry("YourHost.yourdomain"); 
Console.WriteLine($"IP: {entry.AddressList.First()} hostName: {entry.HostName}");