title: C# - How do you find the DMARC and DOMAIN KEYS (DKIM) mail records of a domain using C#?
body: <p>I'm building a C# Console application in VS that asks a user to enter a domain <em>e.g. example.net</em> and returns all the mail records (A, MX, SPF, DMARC, DKIM, CNAME)</p>
  
  <p>I have used the example below which will return a string of the SPF TXT records, but does not return the DMARC and DKIM TXT records.. Strange? - Or not? </p>
  
  <p>I'm after the <code>_domainkey.example.net</code> and <code>k1._domainkey.example.net</code> (DKIM).</p>
  
  <p>I'm after the <code>_dmarc.example.net</code> (DMARC).</p>
  
  <pre><code>private static IList&lt;string&gt; GetTxtRecords(string hostname)
          {
              IList&lt;string&gt; txtRecords = new List&lt;string&gt;();
              string output;
              string pattern = string.Format(@"{0}\s*text =\s*""([\w\-\=]*)""", hostname);
  
              var startInfo = new ProcessStartInfo("nslookup");
              startInfo.Arguments = string.Format("-type=TXT {0}", hostname);
              startInfo.RedirectStandardOutput = true;
              startInfo.UseShellExecute = false;
              startInfo.WindowStyle = ProcessWindowStyle.Hidden;
  
              using (var cmd = Process.Start(startInfo))
              {
                  output = cmd.StandardOutput.ReadToEnd();
              }
  
              MatchCollection matches = Regex.Matches(output, pattern, RegexOptions.IgnoreCase);
              foreach (Match match in matches)
              {
                  if (match.Success)
                      txtRecords.Add(match.Groups[1].Value);
              }
  
              return txtRecords;
          }
  </code></pre>
  
  <p>How do I get the DMARC and DOMAIN KEY (DKIM) Mail Records?</p>