Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/hakluke/dnstrace

go 1.16

require (
github.com/miekg/dns v1.1.43
github.com/rs/dnstrace v1.4.1
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
github.com/rs/dnstrace v1.4.1 h1:o6W+8hO9kGcdq9FZAVudpCyw6WXeD9XXamXyYiei/Hs=
github.com/rs/dnstrace v1.4.1/go.mod h1:pFQiHK1kt94r2csi+qAxUsJ58r74QbN2q4JCDuFYTeY=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
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=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 h1:cEhElsAv9LUt9ZUUocxzWe05oFLVd+AA2nstydTeI8g=
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
63 changes: 47 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func init() {

func main() {
color := flag.Bool("color", true, "Enable/disable colors")
nsonly := flag.Bool("nsonly", false, "Only print nameservers")
flag.Parse()

if flag.NArg() < 2 || flag.NArg() > 3 {
Expand Down Expand Up @@ -90,13 +91,21 @@ func main() {
qname := m.Question[0].Name
qtype := dns.TypeToString[m.Question[0].Qtype]
if i > 1 {
fmt.Println()
if !*nsonly {
fmt.Println()
}
}
if !*nsonly {
fmt.Printf("%d - query %s %s", i, qtype, qname)
}
fmt.Printf("%d - query %s %s", i, qtype, qname)
if r != nil {
fmt.Printf(": %s", strings.Replace(strings.Replace(r.MsgHdr.String(), ";; ", "", -1), "\n", ", ", -1))
if !*nsonly {
fmt.Printf(": %s", strings.Replace(strings.Replace(r.MsgHdr.String(), ";; ", "", -1), "\n", ", ", -1))
}
}
if !*nsonly {
fmt.Println()
}
fmt.Println()
for _, pr := range rs {
ln := 0
if pr.Msg != nil {
Expand All @@ -107,17 +116,25 @@ func main() {
if pr.Server.HasGlue {
lrtt = "0ms (from glue)"
} else if pr.Server.LookupRTT > 0 {
lrtt = fmt.Sprintf("%.2fms", float64(pr.Server.LookupRTT)/float64(time.Millisecond))
if !*nsonly {
lrtt = fmt.Sprintf("%.2fms", float64(pr.Server.LookupRTT)/float64(time.Millisecond))
}
}
if !*nsonly {
fmt.Printf(col(" - %d bytes in %.2fms + %s lookup on %s(%s)", cDarkGray), ln, rtt, lrtt, pr.Server.Name, pr.Addr)
}
fmt.Printf(col(" - %d bytes in %.2fms + %s lookup on %s(%s)", cDarkGray), ln, rtt, lrtt, pr.Server.Name, pr.Addr)
if pr.Err != nil {
err := pr.Err
if oerr, ok := err.(*net.OpError); ok {
err = oerr.Err
}
fmt.Printf(": %v", col(err, cRed))
if !*nsonly {
fmt.Printf(": %v", col(err, cRed))
}
}
if !*nsonly {
fmt.Print("\n")
}
fmt.Print("\n")
}

switch rtype {
Expand All @@ -133,15 +150,26 @@ func main() {
for _, s := range ns {
var glue string
if s.HasGlue {
glue = col("glue: "+strings.Join(s.Addrs, ","), cDarkGray)
if !*nsonly {
glue = col("glue: "+strings.Join(s.Addrs, ","), cDarkGray)
}
} else {
if !*nsonly {
glue = col("no glue", cYellow)
}
}
if !*nsonly {
fmt.Printf("%s %d NS %s (%s)\n", label, s.TTL, s.Name, glue)
} else {
glue = col("no glue", cYellow)
// just print the nameserver hostname without any details
fmt.Printf("%s\n", s.Name)
}
fmt.Printf("%s %d NS %s (%s)\n", label, s.TTL, s.Name, glue)
}
case client.ResponseTypeCNAME:
for _, rr := range r.Answer {
fmt.Println(rr)
if !*nsonly {
fmt.Println(rr)
}
}
}
},
Expand All @@ -154,10 +182,13 @@ func main() {
fmt.Printf(col("*** error: %v\n", cRed), err)
os.Exit(1)
}

fmt.Println()
fmt.Printf(col(";; Cold best path time: %s\n\n", cGray), rtt)
if !*nsonly {
fmt.Println()
fmt.Printf(col(";; Cold best path time: %s\n\n", cGray), rtt)
}
for _, rr := range r.Answer {
fmt.Println(rr)
if !*nsonly {
fmt.Println(rr)
}
}
}