简体   繁体   English

C#如何在不使用WMI的情况下查询Windows DNS服务器以获取rrecord

[英]C# How to query Windows DNS Server for a rrecord without using WMI

Is there a way that I can search a Dns server for an record without using WMI to make the connection to the Dns server using .NET 4,5? 有没有办法可以在不使用WMI使用.NET 4,5连接到Dns服务器的情况下搜索Dns服务器的记录?

I have this fully working with Wmi in .NET 4.5 but find it to be way too slow (even when caching the connections). 我在.NET 4.5中完全使用Wmi,但发现它太慢了(甚至在缓存连接时)。 It's too inconsistent. 这太不协调了。 Some search queries are 2 seconds while others are over 100 seconds. 一些搜索查询是2秒,而其他搜索查询超过100秒。

And as far as I know I can't optimize the query any further. 据我所知,我无法进一步优化查询。

Query:  string query = "SELECT * FROM " + propertiesStruct.Table + " WHERE ContainerName = '" + domain + "' AND OwnerName ='" + name + "." + domain + "'";

So I'm looking for a way to connect to the dns server, query it for a dns record by name and domain and get back the same/similar data as a WMI query if possible. 所以我正在寻找一种连接到dns服务器的方法,通过名称和域查询dns记录,并在可能的情况下获取与WMI查询相同/相似的数据。

I've looked at .NET 4.5 System.Net.Dns class and methods but find it does not give enough information back. 我查看了.NET 4.5 System.Net.Dns类和方法,但发现它没有提供足够的信息。 ( https://msdn.microsoft.com/en-us/library/ms143998%28v=vs.110%29.aspx ) https://msdn.microsoft.com/en-us/library/ms143998%28v=vs.110%29.aspx

Information I'm looking to get back are: Example - 我想要回来的信息是:示例 -

DNS Record fqdn - stackoverflow.com DNS记录fqdn - stackoverflow.com

DNS Record Name - stackoverflow DNS记录名称 - stackoverflow

DNS Domain/Zone - com DNS域/区域 - com

DNS Record value - 198.252.206.140 DNS记录值 - 198.252.206.140

DNS Record type - A/AAAA/CNAME/PTR DNS记录类型 - A / AAAA / CNAME / PTR

DNS Record ttl - 3600 DNS记录ttl - 3600

Even if it returns all the records with the same fqdn but different values because of it being a different record type that is fine I can filter the results manually for the type I'm looking for. 即使它返回具有相同fqdn但不同值的所有记录,因为它是一个不同的记录类型,我可以手动过滤结果我正在寻找的类型。

Closest thing I have found is a Linux dig but this has to be done in .net on a windows server. 我发现最近的东西是Linux挖掘,但这必须在Windows服务器上的.net中完成。

Thanks 谢谢

If you can use p/invoke, then there's the DNSAPI library/DLL. 如果你可以使用p / invoke,那么就是DNSAPI库/ DLL。 See DNSAPI on pinvoke.net . 请参阅pinvoke.net上的DNSAPI Some of the options suggest that the DnsQuery method can use the dns-cache, and also that use of the cache can be turned off. 一些选项表明DnsQuery方法可以使用dns-cache,并且可以关闭缓存的使用。 I've used this API successfully, but we warned, it's a pretty low level. 我已成功使用此API,但我们警告说,这是一个相当低的水平。 As an example, if you want to do reverse lookup, you probably have to assemble the query explicitly (that is, for 192.168.0.1, use a query of type PTR for "1.0.168.192.in-addr.arpa" ). 例如,如果要进行反向查找,则可能必须显式组装查询(即,对于192.168.0.1,使用类型为PTR的查询“1.0.168.192.in-addr.arpa”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM