I'm building a C# Console application in VS that asks a user to enter a domain e.g. example.net and returns all the mail records (A, MX, SPF, DMARC, DKIM, CNAME)
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?
I'm after the _domainkey.example.net
and k1._domainkey.example.net
(DKIM).
I'm after the _dmarc.example.net
(DMARC).
private static IList<string> GetTxtRecords(string hostname)
{
IList<string> txtRecords = new List<string>();
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;
}
How do I get the DMARC and DOMAIN KEY (DKIM) Mail Records?