Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elapsed time in JSON output #61

Merged
merged 4 commits into from
Jan 24, 2024
Merged
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: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# dnslookup

Simple command line utility to make DNS lookups. Supports all known DNS
protocols: plain DNS, DoH, DoT, DoQ, DNSCrypt.
protocols: plain DNS, plain DNS-over-TCP, DoH, DoT, DoQ, DNSCrypt.

### How to install

Expand Down Expand Up @@ -35,6 +35,12 @@ Plain DNS:
dnslookup example.org 94.140.14.14
```

Plain DNS-over-TCP:

```shell
dnslookup example.org tcp://94.140.14.14
```

DNS-over-TLS:

```shell
Expand Down
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import (
"github.com/miekg/dns"
)

type jsonMsg struct {
dns.Msg
Elapsed time.Duration `json:"elapsed"`
}

// VersionString -- see the makefile
var VersionString = "master"

Expand Down Expand Up @@ -171,8 +176,15 @@ func main() {
os.Stdout.WriteString(msg)
os.Stdout.WriteString(reply.String() + "\n")
} else {
// Prevent JSON parsing from skewing results
endTime := time.Now()

var JSONreply jsonMsg
JSONreply.Msg = *reply
JSONreply.Elapsed = endTime.Sub(startTime)

var b []byte
b, err = json.MarshalIndent(reply, "", " ")
b, err = json.MarshalIndent(JSONreply, "", " ")
if err != nil {
log.Fatalf("Cannot marshal json: %s", err)
}
Expand Down Expand Up @@ -285,7 +297,7 @@ func getRRType() (rrType uint16) {
func usage() {
os.Stdout.WriteString("Usage: dnslookup <domain> <server> [<providerName> <serverPk>]\n")
os.Stdout.WriteString("<domain>: mandatory, domain name to lookup\n")
os.Stdout.WriteString("<server>: mandatory, server address. Supported: plain, tls:// (DOT), https:// (DOH), sdns:// (DNSCrypt), quic:// (DOQ)\n")
os.Stdout.WriteString("<server>: mandatory, server address. Supported: plain, tcp:// (TCP), tls:// (DOT), https:// (DOH), sdns:// (DNSCrypt), quic:// (DOQ)\n")
os.Stdout.WriteString("<providerName>: optional, DNSCrypt provider name\n")
os.Stdout.WriteString("<serverPk>: optional, DNSCrypt server public key\n")
}
Expand Down