title: C# How to query Windows DNS Server for a rrecord without using WMI
body: <p>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?</p>
  
  <p>I have this fully working with Wmi in .NET 4.5 but find it to be way too slow (even when caching the connections).  It's too inconsistent.  Some search queries are 2 seconds while others are over 100 seconds.</p>
  
  <p>And as far as I know I can't optimize the query any further.  </p>
  
  <pre><code>Query:  string query = "SELECT * FROM " + propertiesStruct.Table + " WHERE ContainerName = '" + domain + "' AND OwnerName ='" + name + "." + domain + "'";
  </code></pre>
  
  <p>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.   </p>
  
  <p>I've looked at .NET 4.5 System.Net.Dns class and methods but find it does not give enough information back.  (<a href="https://msdn.microsoft.com/en-us/library/ms143998%28v=vs.110%29.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/ms143998%28v=vs.110%29.aspx</a>)</p>
  
  <p>Information I'm looking to get back are: Example - </p>
  
  <p>DNS Record fqdn - stackoverflow.com</p>
  
  <p>DNS Record Name - stackoverflow</p>
  
  <p>DNS Domain/Zone - com</p>
  
  <p>DNS Record value - 198.252.206.140</p>
  
  <p>DNS Record type - A/AAAA/CNAME/PTR</p>
  
  <p>DNS Record ttl - 3600</p>
  
  <p>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.</p>
  
  <p>Closest thing I have found is a Linux dig but this has to be done in .net on a windows server.  </p>
  
  <p>Thanks</p>