SPF Lookup in Go

In this gist, We will check how we can extract SPF records in Go.


Go version

$ go version
go version go1.13 linux/amd64


DNS Library(https://github.com/miekg/dns)

Install dependency

$ go get github.com/miekg/dns 


Here you can change nameserver according to your requirement. I have specified here google’s name server ( You can also use cloudflare’s nameserver (


You can make any DNS query with miekg/dns library. In the above script, we have looked up TXT Records and then we have searched for a string containing v=spf1.