Skip to content

Commit

Permalink
- Update deps
Browse files Browse the repository at this point in the history
- Fix glaring lint issues
  • Loading branch information
dkorunic committed Nov 4, 2022
1 parent 8fc2773 commit 9a58034
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 51 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
dnstrace
===
# dnstrace

[![GitHub license](https://img.shields.io/github/license/dkorunic/dnstrace.svg)](https://github.com/dkorunic/dnstrace/blob/master/LICENSE.txt)
[![GitHub release](https://img.shields.io/github/release/dkorunic/dnstrace.svg)](https://github.com/dkorunic/dnstrace/releases/latest)
[![Build Status](https://travis-ci.org/dkorunic/dnstrace.svg)](https://travis-ci.org/dkorunic/dnstrace)
[![Go Report Card](https://goreportcard.com/badge/github.com/dkorunic/dnstrace)](https://goreportcard.com/report/github.com/dkorunic/dnstrace)


## About

`dnstrace` is yet another DNS query/response tracing tool. Its purpose is to emulate iterative (with RD flag being unset) DNS queries usually being sent from any DNS recursor and traverse DNS authoritative hierarchy in search for the given query name and query type, assuming IN class. It will display every query and response, indicating reasons (delegations, CNAME following, missing glue etc.) for any new sub-query and additionally displaying individual and total response time.
Expand All @@ -28,7 +26,7 @@ Download your preferred flavor from [the releases](https://github.com/dkorunic/d
### Using go get

```shell
go get github.com/dkorunic/dnstrace
go install github.com/dkorunic/dnstrace@latest
```

## Usage
Expand Down
7 changes: 4 additions & 3 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
package cache

import (
"github.com/miekg/dns"
"github.com/sean-/seed"
"math/rand"
"strings"
"sync"

"github.com/miekg/dns"
"github.com/sean-/seed"
)

type Cache struct {
Expand All @@ -35,7 +36,7 @@ type Cache struct {
}

func init() {
seed.Init()
_, _ = seed.Init()
}

// New returns a new and initialized A dns cache
Expand Down
17 changes: 8 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
module github.com/dkorunic/dnstrace

go 1.18
go 1.19

require (
github.com/fatih/color v1.13.0
github.com/miekg/dns v1.1.48
github.com/miekg/dns v1.1.50
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529
)

require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd // indirect
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/tools v0.2.0 // indirect
)
30 changes: 15 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/miekg/dns v1.1.48 h1:Ucfr7IIVyMBz4lRE8qmGUuZ4Wt3/ZGu9hmcMT3Uu4tQ=
github.com/miekg/dns v1.1.48/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd h1:zYlwaUHTmxuf6H7hwO2dgwqozQmH7zf4x+/qql4oVWc=
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -34,19 +35,18 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f h1:rlezHXNlxYWvBCzNses9Dlc7nGFaNMJeqLolcmQSSZY=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6 changes: 4 additions & 2 deletions hints/hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
package hints

import (
"github.com/sean-/seed"
"math/rand"

"github.com/sean-/seed"
)

type Root struct {
Expand Down Expand Up @@ -55,7 +56,8 @@ func New() *Hints {
{"j.root-servers.net.", "192.58.128.30", "2001:503:c27::2:30"},
{"k.root-servers.net.", "193.0.14.129", "2001:7fd::1"},
{"l.root-servers.net.", "199.7.83.42", "2001:500:3::42"},
{"m.root-servers.net.", "202.12.27.33", "2001:dc3::35"}}}
{"m.root-servers.net.", "202.12.27.33", "2001:dc3::35"},
}}
}

// Get returns an array of root nameserver hints
Expand Down
4 changes: 2 additions & 2 deletions ipify.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package main

import (
"io/ioutil"
"io"
"net/http"
"time"
)
Expand All @@ -43,7 +43,7 @@ func getIpify() string {
}
defer resp.Body.Close()

ip, err := ioutil.ReadAll(resp.Body)
ip, err := io.ReadAll(resp.Body)
if err != nil {
return ""
}
Expand Down
36 changes: 20 additions & 16 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ Retry:
// Update A cache from A type RRs in ADDITIONAL section
for _, rr := range r.Extra {
if rr.Header().Rrtype == dns.TypeA {
rrn := strings.ToLower(rr.Header().Name)
aCache.Add(rrn, rr.(*dns.A))
if a, ok := rr.(*dns.A); ok {
rrn := strings.ToLower(rr.Header().Name)
aCache.Add(rrn, a)
}
}
}

Expand All @@ -186,21 +188,23 @@ Retry:
if len(rrCnameSub) > 0 {
color.Green("Got CNAME in response:")
for _, rr := range rrCnameSub {
color.Green("%v", rr)
color.Cyan("~ Following CNAME: %q/CNAME -> %q", rr.Header().Name,
rr.(*dns.CNAME).Target)

// In-zone CNAME target so we can continue with current nameserver
if strings.HasSuffix(rr.(*dns.CNAME).Target, "."+zone) {
if c, ok := rr.(*dns.CNAME); ok {
color.Green("%v", rr)
color.Cyan("~ Following CNAME: %q/CNAME -> %q", rr.Header().Name,
c.Target)

// In-zone CNAME target so we can continue with current nameserver
if strings.HasSuffix(c.Target, "."+zone) {
fmt.Printf("\n")
return doDNSQuery(c.Target, qtype, nsIP, nsLabel, zone, rtt+rttIn, sub)
}

// Start sub-query from the root nameservers
nsLabel, nsIP, _ = roots.GetRand()
color.Yellow("~ Out of zone CNAME target, sub-query will restart from \".\"")
fmt.Printf("\n")
return doDNSQuery(rr.(*dns.CNAME).Target, qtype, nsIP, nsLabel, zone, rtt+rttIn, sub)
return doDNSQuery(c.Target, qtype, nsIP, nsLabel, ".", rtt+rttIn, sub)
}

// Start sub-query from the root nameservers
nsLabel, nsIP, _ = roots.GetRand()
color.Yellow("~ Out of zone CNAME target, sub-query will restart from \".\"")
fmt.Printf("\n")
return doDNSQuery(rr.(*dns.CNAME).Target, qtype, nsIP, nsLabel, ".", rtt+rttIn, sub)
}
}

Expand Down Expand Up @@ -259,7 +263,7 @@ Retry:
func getRRset(rr []dns.RR, qname string, qtype uint16) []dns.RR {
var rr1 []dns.RR
for _, rr := range rr {
if strings.ToLower(rr.Header().Name) == strings.ToLower(qname) && rr.Header().Rrtype == qtype {
if strings.EqualFold(rr.Header().Name, qname) && rr.Header().Rrtype == qtype {
rr1 = append(rr1, rr)
}
}
Expand Down

0 comments on commit 9a58034

Please sign in to comment.