initial commit from their example
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
commit
0f61a07c76
2 changed files with 44 additions and 0 deletions
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module git.thisco.de/vbatts/home0
|
||||
|
||||
go 1.16
|
||||
|
||||
require github.com/Focinfi/go-dns-resolver v1.0.0
|
39
main.go
Normal file
39
main.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
dns "github.com/Focinfi/go-dns-resolver"
|
||||
)
|
||||
|
||||
func main() {
|
||||
domains := []string{"google.com", "twitter.com"}
|
||||
types := []dns.QueryType{dns.TypeA, dns.TypeNS, dns.TypeMX, dns.TypeTXT}
|
||||
|
||||
// Set timeout and retry times
|
||||
dns.Config.SetTimeout(uint(2))
|
||||
dns.Config.RetryTimes = uint(4)
|
||||
|
||||
// Simple usage
|
||||
if results, err := dns.Exchange("google.com", "119.29.29.29", dns.TypeA); err == nil {
|
||||
for _, r := range results {
|
||||
log.Println(r.Record, r.Type, r.Ttl, r.Priority, r.Content)
|
||||
}
|
||||
} else {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Create and setup resolver with domains and types
|
||||
resolver := dns.NewResolver("119.29.29.29")
|
||||
resolver.Targets(domains...).Types(types...)
|
||||
// Lookup
|
||||
res := resolver.Lookup()
|
||||
|
||||
//res.ResMap is a map[string]*ResultItem, key is the domain
|
||||
for target := range res.ResMap {
|
||||
log.Printf("%v: \n", target)
|
||||
for _, r := range res.ResMap[target] {
|
||||
log.Println(r.Record, r.Type, r.Ttl, r.Priority, r.Content)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue