Get SPF records from a Domain

前端 未结 7 1335
面向向阳花
面向向阳花 2021-02-14 01:20

What are the ways to Check SPF records on a domain?

There is a website where i can do it manually using - http://www.mxtoolbox.com/SuperTool.aspx

How can i do it

7条回答
  •  悲哀的现实
    2021-02-14 01:57

    I have the same problem, and managed to find two three solutions:

    The nslookup solution

    You can get the SPF by typing the following command in the command line:

    nslookup -type=TXT 
    

    You can automate this in C# using System.Diagonstics.Process, as described in this blog post.

    The DNS.NET Resolver project

    I found this CodeProject article about DNS resolution. It comes with demo project. I ran the project and got the following result for stackexchange.com:

    DNS Dig screeenshot

    Note: Make sure that the QType field is set to TXT before you press the Send button

    The section highlighted in yellow represents the SPF record. I haven't yet dug into the code to see how it's done, but this seems like a good alternative to the nslookup solution above.

    [Update] The ARSoft.Tools.Net project

    If all you need to do is check whether a domain supports a mail server, you can use the ARSoft.Tools.Net library (also available as a NuGet Package).

    After installing the package, I managed to perform the SPF check with this code:

    var spfValidator = new ARSoft.Tools.Net.Spf.SpfValidator();
    
    var mailIpAddress = IPAddress.Parse("X.X.X.X");
    var domain = "example.com";
    var senderAddress = "sender@example.com";
    
    ARSoft.Tools.Net.Spf.SpfQualifier result = 
        spfValidator.CheckHost(mailIpAddress, domain, senderAddress);
    

提交回复
热议问题