Skip to content

Instantly share code, notes, and snippets.

@ashishtiwari1993
Last active August 2, 2020 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashishtiwari1993/ea5da5581ae2c56f3e25f8509155bd37 to your computer and use it in GitHub Desktop.
Save ashishtiwari1993/ea5da5581ae2c56f3e25f8509155bd37 to your computer and use it in GitHub Desktop.
SPF Lookup in Go
package main
import (
"github.com/miekg/dns"
"strings"
"fmt"
)
func main() {
domain := "google.com" // Define domain
nameserver := "8.8.8.8" // Define nameserver as per your requirement
c := dns.Client{}
m := dns.Msg{}
m.SetQuestion(domain+".", dns.TypeTXT)
l, _, err := c.Exchange(&m, nameserver+":53")
if err != nil {
fmt.Print(err.Error())
}
spf := []string{}
for _, ans := range l.Answer {
x := ans.(*dns.TXT)
for _, t := range x.Txt {
if strings.Contains(t, "v=spf1") {
spf = append(spf, t)
}
}
}
fmt.Println(spf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment