diff options
| author | Shulhan <ms@kilabit.info> | 2019-03-02 07:30:58 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-03-02 07:30:58 +0700 |
| commit | 35066f79a4844d207057f452eaddf4f0a11c0821 (patch) | |
| tree | e028687732acc7c54790be54ceb97dff06e4bbef | |
| parent | da44b655f1e46281741e47a664cd96ed560e4cb9 (diff) | |
| download | rescached-35066f79a4844d207057f452eaddf4f0a11c0821.tar.xz | |
cmd/resolver: generate unique request ID
Also, fix the name server that being requested on error.
| -rw-r--r-- | cmd/resolver/main.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go index 5d268ee..6af3f47 100644 --- a/cmd/resolver/main.go +++ b/cmd/resolver/main.go @@ -7,6 +7,7 @@ package main import ( "fmt" "log" + "math/rand" "net" "strings" "time" @@ -116,9 +117,13 @@ func lookup(opts *options, ns string, timeout time.Duration, qname []byte) *dns. log.Fatal("! dns.NewUDPClient: ", err) } } + + rand.Seed(time.Now().Unix()) + cl.SetTimeout(timeout) req := dns.NewMessage() + req.Header.ID = uint16(rand.Intn(65535)) req.Question.Name = qname req.Question.Type = opts.qtype req.Question.Class = opts.qclass @@ -175,8 +180,8 @@ func main() { } var ( - res *dns.Message - nameserver string + res *dns.Message + ns string ) nsAddrs := parseNameServers(cr.NameServers) @@ -192,7 +197,6 @@ func main() { for _, qname := range queries { for x := 0; x < cr.Attempts; x++ { for _, addr := range nsAddrs { - var ns string if opts.doh { ns = fmt.Sprintf("https://%s/dns-query", addr.IP) } else { @@ -211,6 +215,6 @@ func main() { out: if res != nil { - println(messagePrint(nameserver, res)) + println(messagePrint(ns, res)) } } |
