Skip to content

Commit 5aee2d2

Browse files
radulucutmr-karan
authored andcommitted
add support for --json, --short && update docs
1 parent 020d3de commit 5aee2d2

File tree

8 files changed

+248
-16
lines changed

8 files changed

+248
-16
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<img src="www/static/doggo.png" alt="doggo CLI usage">
1515
</p>
1616

17-
1817
---
1918

2019
**doggo** is a modern command-line DNS client (like _dig_) written in Golang. It outputs information in a neat concise manner and supports protocols like DoH, DoT, DoQ, and DNSCrypt as well.
@@ -79,6 +78,9 @@ doggo example.com --json | jq '.responses[0].answers[].address'
7978

8079
# Reverse DNS lookup
8180
doggo --reverse 8.8.8.8 --short
81+
82+
# Using Globalping
83+
doggo example.com --from Germany,Japan --limit 2
8284
```
8385

8486
## Features

cmd/doggo/cli.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ func main() {
5050
logger.Error("Error fetching globalping measurement", "error", err)
5151
os.Exit(2)
5252
}
53-
err = app.OutputGlobalping(res)
53+
if app.QueryFlags.ShowJSON {
54+
err = app.OutputGlobalpingJSON(res)
55+
} else if app.QueryFlags.ShortOutput {
56+
err = app.OutputGlobalpingShort(res)
57+
} else {
58+
err = app.OutputGlobalping(res)
59+
}
5460
if err != nil {
5561
logger.Error("Error outputting globalping measurement", "error", err)
5662
os.Exit(2)
@@ -137,7 +143,7 @@ func setupFlags() *flag.FlagSet {
137143
f.BoolP("reverse", "x", false, "Performs a DNS Lookup for an IPv4 or IPv6 address")
138144

139145
f.String("from", "", "Probe locations as a comma-separated list")
140-
f.Int("limit", 1, "Limit the number of responses")
146+
f.Int("limit", 1, "Limit the number of probes to use")
141147

142148
f.DurationP("timeout", "T", 5*time.Second, "Sets the timeout for a query")
143149
f.Bool("search", true, "Use the search list provided in resolv.conf")

cmd/doggo/completions.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _doggo() {
1313
cur="${COMP_WORDS[COMP_CWORD]}"
1414
prev="${COMP_WORDS[COMP_CWORD-1]}"
1515
16-
opts="-v --version -h --help -q --query -t --type -n --nameserver -c --class -r --reverse --strategy --ndots --search --timeout -4 --ipv4 -6 --ipv6 --tls-hostname --skip-hostname-verification -J --json --short --color --debug --time"
16+
opts="-v --version -h --help -q --query -t --type -n --nameserver -c --class -r --reverse --strategy --ndots --search --timeout -4 --ipv4 -6 --ipv6 --tls-hostname --skip-hostname-verification -J --json --short --color --debug --time --from --limit"
1717
1818
case "${prev}" in
1919
-t|--type)
@@ -77,6 +77,8 @@ _doggo() {
7777
'--color[Colored output]:setting:(true false)' \
7878
'--debug[Enable debug logging]' \
7979
'--time[Shows how long the response took from the server]' \
80+
'--from[Query using Globalping API from a specific location]' \
81+
'--limit[Limit the number of probes to use from Globalping]' \
8082
'*:hostname:_hosts' \
8183
&& ret=0
8284
@@ -131,6 +133,10 @@ complete -c doggo -n '__fish_doggo_no_subcommand' -l 'time' -d "Shows ho
131133
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'tls-hostname' -d "Hostname for certificate verification" -x -a "(__fish_print_hostnames)"
132134
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'skip-hostname-verification' -d "Skip TLS hostname verification in case of DoT lookups"
133135
136+
# Globalping options
137+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'from' -d "Query using Globalping API from a specific location"
138+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'limit' -d "Limit the number of probes to use from Globalping"
139+
134140
# Completions command
135141
complete -c doggo -n '__fish_doggo_no_subcommand' -a completions -d "Generate shell completion scripts"
136142
complete -c doggo -n '__fish_seen_subcommand_from completions' -a "bash zsh fish" -d "Shell type"

cmd/doggo/help.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ var appHelpTextTemplate = `{{ "NAME" | color "" "heading" }}:
5858
{{- range $opt := .OutputOptions }}
5959
{{ printf "%-30s" $opt.Flag | color "yellow" "" }}{{ $opt.Description }}
6060
{{- end }}
61+
62+
{{ "GLOBALPING OPTIONS" | color "" "heading" }}:
63+
{{- range $opt := .GlobalPingOptions }}
64+
{{ printf "%-30s" $opt.Flag | color "yellow" "" }}{{ $opt.Description }}
65+
{{- end }}
6166
`
6267

6368
func renderCustomHelp() {
@@ -89,6 +94,7 @@ func renderCustomHelp() {
8994
{"-q mrkaran.dev -t MX -n 1.1.1.1", "Using named arguments."},
9095
{"mrkaran.dev --aa --ad", "Query with Authoritative Answer and Authenticated Data flags set."},
9196
{"mrkaran.dev --cd --do", "Query with Checking Disabled and DNSSEC OK flags set."},
97+
{"mrkaran.dev --from Germany", "Query using Globalping API from a specific location."},
9298
},
9399
"TransportOptions": []TransportOption{
94100
{"@udp://", "eg: @1.1.1.1", "initiates a UDP query to 1.1.1.1:53."},
@@ -134,6 +140,10 @@ func renderCustomHelp() {
134140
{"--debug", "Enable debug logging."},
135141
{"--time", "Shows how long the response took from the server."},
136142
},
143+
"GlobalPingOptions": []Option{
144+
{"--from=Germany", "Query using Globalping API from a specific location."},
145+
{"--limit=INT", "Limit the number of probes to use from Globalping."},
146+
},
137147
}
138148

139149
tmpl, err := template.New("help").Funcs(template.FuncMap{

docs/src/content/docs/features/output.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ mrkaran.dev. A IN 300s 104.21.7.168 127.0.0.53:53
1616
mrkaran.dev. A IN 300s 172.67.187.239 127.0.0.53:53
1717
```
1818

19+
```bash
20+
doggo mrkaran.dev --from Europe,Asia --limit 2
21+
LOCATION NAME TYPE CLASS TTL ADDRESS NAMESERVER
22+
Vienna, AT, EU, EDIS GmbH
23+
(AS57169)
24+
mrkaran.dev. A IN 300s 104.21.7.168 private
25+
mrkaran.dev. A IN 300s 172.67.187.239 private
26+
Tokyo, JP, AS, Tencent
27+
Building, Kejizhongyi Avenue
28+
(AS132203)
29+
mrkaran.dev. A IN 300s 104.21.7.168 private
30+
mrkaran.dev. A IN 300s 172.67.187.239 private
31+
```
32+
1933
To disable colored output, use the `--color=false` flag:
2034

2135
```bash
@@ -42,7 +56,7 @@ doggo internetfreedom.in --json | jq
4256
"address": "104.27.158.96",
4357
"rtt": "37ms",
4458
"nameserver": "127.0.0.1:53"
45-
},
59+
}
4660
// ... more entries ...
4761
],
4862
"queries": [
@@ -56,6 +70,49 @@ doggo internetfreedom.in --json | jq
5670
}
5771
```
5872

73+
```bash
74+
doggo mrkaran.dev --from Europe,Asia --limit 2 --json | jq
75+
```
76+
77+
```json
78+
{
79+
"responses": [
80+
{
81+
"location": "Groningen, NL, EU, Google LLC (AS396982)",
82+
"answers": [
83+
{
84+
"name": "mrkaran.dev.",
85+
"type": "A",
86+
"class": "IN",
87+
"ttl": "300s",
88+
"address": "172.67.187.239",
89+
"status": "",
90+
"rtt": "",
91+
"nameserver": "private"
92+
}
93+
// ... more entries ...
94+
]
95+
},
96+
{
97+
"location": "Jakarta, ID, AS, Zenlayer Inc (AS21859)",
98+
"answers": [
99+
{
100+
"name": "mrkaran.dev.",
101+
"type": "A",
102+
"class": "IN",
103+
"ttl": "300s",
104+
"address": "172.67.187.239",
105+
"status": "",
106+
"rtt": "",
107+
"nameserver": "private"
108+
}
109+
// ... more entries ...
110+
]
111+
}
112+
]
113+
}
114+
```
115+
59116
### Short Output
60117

61118
For a more concise view, use the `--short` flag to show only the response section:
@@ -65,3 +122,13 @@ doggo mrkaran.dev --short
65122
104.21.7.168
66123
172.67.187.239
67124
```
125+
126+
```bash
127+
doggo mrkaran.dev --from Europe,Asia --limit 2 --short
128+
Frankfurt, DE, EU, WIBO Baltic UAB (AS59939)
129+
104.21.7.168
130+
172.67.187.239
131+
Saratov, RU, AS, LLC "SMART CENTER" (AS48763)
132+
172.67.187.239
133+
104.21.7.168
134+
```

docs/src/content/docs/guide/examples.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,75 @@ These examples showcase how to combine different features for powerful DNS query
88
## Basic Queries
99

1010
1. Simple A record lookup:
11+
1112
```bash
1213
doggo example.com
1314
```
1415

1516
2. Query for a specific record type:
17+
1618
```bash
1719
doggo AAAA example.com
1820
```
1921

2022
3. Query multiple record types simultaneously:
23+
2124
```bash
2225
doggo A AAAA MX example.com
2326
```
2427

28+
4. Query using Globalping API from a specific location:
29+
```bash
30+
doggo example.com --from Germany
31+
```
32+
2533
### Using Different Resolvers
2634

2735
4. Query using a specific DNS resolver:
36+
2837
```bash
2938
doggo example.com @1.1.1.1
3039
```
3140

3241
5. Use DNS-over-HTTPS (DoH):
42+
3343
```bash
3444
doggo example.com @https://cloudflare-dns.com/dns-query
3545
```
3646

3747
6. Use DNS-over-TLS (DoT):
48+
3849
```bash
3950
doggo example.com @tls://1.1.1.1
4051
```
4152

4253
7. Query multiple resolvers and compare results:
54+
4355
```bash
4456
doggo example.com @1.1.1.1 @8.8.8.8 @9.9.9.9
4557
```
4658

59+
8. Using Globalping API
60+
```bash
61+
doggo example.com @1.1.1.1 --from Germany
62+
```
63+
4764
### Advanced Queries
4865

4966
8. Perform a reverse DNS lookup:
67+
5068
```bash
5169
doggo --reverse 8.8.8.8
5270
```
5371

5472
9. Set query flags for DNSSEC validation:
73+
5574
```bash
5675
doggo example.com --do --cd
5776
```
5877

5978
10. Use the short output format for concise results:
79+
6080
```bash
6181
doggo example.com --short
6282
```
@@ -69,11 +89,13 @@ These examples showcase how to combine different features for powerful DNS query
6989
### Combining Flags
7090

7191
12. Perform a reverse lookup with short output and custom resolver:
92+
7293
```bash
7394
doggo --reverse 8.8.8.8 --short @1.1.1.1
7495
```
7596

7697
13. Query for MX records using DoH with JSON output:
98+
7799
```bash
78100
doggo MX example.com @https://dns.google/dns-query --json
79101
```
@@ -83,7 +105,6 @@ These examples showcase how to combine different features for powerful DNS query
83105
doggo AAAA example.com -6 --timeout 3s --do
84106
```
85107

86-
87108
## Scripting and Automation
88109

89110
16. Use JSON output for easy parsing in scripts:
@@ -93,16 +114,19 @@ These examples showcase how to combine different features for powerful DNS query
93114
```
94115

95116
17. Batch query multiple domains from a file:
117+
96118
```bash
97119
cat domains.txt | xargs -I {} doggo {} --short
98120
```
99121

100122
18. Find all nameservers for a domain and its parent domains:
123+
101124
```bash
102125
doggo NS example.com example.com. com. . --short
103126
```
104127

105128
19. Extract all MX records and their priorities:
129+
106130
```bash
107131
doggo MX gmail.com --json | jq -r '.responses[0].answers[] | "\(.address) \(.preference)"'
108132
```
@@ -115,36 +139,43 @@ These examples showcase how to combine different features for powerful DNS query
115139
## Troubleshooting and Debugging
116140

117141
21. Enable debug logging for verbose output:
142+
118143
```bash
119144
doggo example.com --debug
120145
```
121146

122147
22. Compare responses with and without EDNS Client Subnet:
148+
123149
```bash
124150
doggo example.com @8.8.8.8
125151
doggo example.com @8.8.8.8 --z
126152
```
127153

128154
23. Test DNSSEC validation:
155+
129156
```bash
130157
doggo rsasecured.net --do @8.8.8.8
131158
```
159+
132160
This example uses a domain known to be DNSSEC-signed. The `--do` flag sets the DNSSEC OK bit.
133161

134162
Note: DNSSEC validation can be complex and depends on various factors:
163+
135164
- The domain must be properly DNSSEC-signed
136165
- The resolver must support DNSSEC
137166
- The resolver must be configured to perform DNSSEC validation
138167

139168
If you don't see DNSSEC-related information in the output, try using a resolver known to support DNSSEC, like 8.8.8.8 (Google) or 9.9.9.9 (Quad9).
140169
141170
24. Compare responses with and without EDNS Client Subnet:
171+
142172
```bash
143173
doggo example.com @8.8.8.8
144174
doggo example.com @8.8.8.8 --z
145175
```
146176
147177
25. Check for DNSSEC records (DNSKEY, DS, RRSIG):
178+
148179
```bash
149180
doggo DNSKEY example.com @8.8.8.8
150181
doggo DS example.com @8.8.8.8

0 commit comments

Comments
 (0)