我在VS中构建了一个C#控制台应用程序,要求用户输入域名example.net并返回所有邮件记录(A,MX,SPF,DMARC,DKIM,CNAME)C# - 如何找到使用C#的域的DMARC和DOMAIN KEYS(DKIM)邮件记录?
我已经使用下面的示例将返回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和域密钥(DKIM)邮件记录?
我并不仅限于此代码,但是这是我迄今为止唯一能够工作的代码?你有什么建议作为替代? DMARC和DKIM记录也是TXT记录,因此它们是否也应该退回? – kingcobra
对不起,我的坏。你是对的....看看这个答案:http://stackoverflow.com/a/25167028/75852。我没有尝试过,但我希望它可以通过将记录类型更改为TXT而不是MX来工作。 – squillman
我建议你使用ARSoft.Tools.Net nuget包来做这些事情,而不是nslookup。 – Evk