我在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