Last active
November 2, 2024 02:25
-
-
Save ashishtiwari1993/ea5da5581ae2c56f3e25f8509155bd37 to your computer and use it in GitHub Desktop.
SPF Lookup in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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