How to Lookup SPF Records for a Domain

SPF, or Sender Policy Framework, takes advantage of the DNS TXT record types to store information about the authorized mail servers for your domain.
ref: http://www.openspf.org/

SPF Records are simple TXT Record types within the DNS System.
string dnsServer = "192.168.0.1";
string domainToResolve = "atgi.com";

// Use NsType.TXT for SPF lookups
DnsQueryRequest request = new DnsQueryRequest();
DnsQueryResponse response = request.Resolve(dnsServer, domainToResolve, NsType.TXT, NsClass.INET, ProtocolType.Udp);

Console.WriteLine("Bytes received: " + response.BytesReceived);

// Enumerate the Answer Records
Console.WriteLine("Answers:");
foreach (IDnsRecord record in response.Answers)
{
    Console.WriteLine(record.Answer);
    Console.WriteLine("  |--- RDATA Field Length: " + record.DnsHeader.DataLength);
    Console.WriteLine("  |--- Name: " + record.DnsHeader.Name);
    Console.WriteLine("  |--- NS Class: " + record.DnsHeader.NsClass);
    Console.WriteLine("  |--- NS Type: " + record.DnsHeader.NsType);
    Console.WriteLine("  |--- TTL: " + record.DnsHeader.TimeToLive);
    Console.WriteLine();
}


Output
Bytes received: 88
Answers:
text: v=spf1 ip4:70.61.58.69 mx a:derrida.atgi.com -all
  |--- RDATA Field Length: 50
  |--- Name: atgi.com.
  |--- NS Class: INET
  |--- NS Type: TXT
  |--- TTL: 1800

Last edited Feb 5, 2008 at 4:01 PM by jmonty, version 7

Comments

No comments yet.