我正在 VS 中构建一个 C# 控制台应用程序,它要求用户输入域,例如 example.net并返回所有邮件记录(A、MX、SPF、DMARC、DKIM、CNAME)
我使用了下面的示例,它将返回 SPF TXT 记录的字符串,但不返回 DMARC 和 DKIM TXT 记录。奇怪?- 或不?
我在_domainkey.example.net
和k1._domainkey.example.net
(DKIM)之后。
我在_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;
}
如何获取 DMARC 和 DOMAIN KEY (DKIM) 邮件记录?