/
ns.go
44 lines (35 loc) · 840 Bytes
/
ns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//go:build !wasm
package cmd
import (
"encoding/json"
"net"
"strings"
"github.com/spf13/cobra"
)
var nsLookupCmd = &cobra.Command{
Use: "nslookup",
Aliases: []string{"lookup", "look"},
Short: "NS lookup",
Long: `NS location IP`,
Run: func(cmd *cobra.Command, args []string) {
ns := getInputStringOrFlag(cmd, args, "ns", false)
asJson := getBoolFlag(cmd, "json", false)
ips := must(net.LookupIP(ns))
res := make([]string, len(ips))
for i, ip := range ips {
val := ip.String()
res[i] = val
}
if asJson {
outputBytes(cmd, must(json.Marshal(res)))
return
}
outputString(cmd, strings.Join(res, "\n"))
},
}
func init() {
pf := nsLookupCmd.PersistentFlags()
pf.StringP("ns", "t", "", "Target namespace")
pf.BoolP("json", "j", false, "As JSON output")
rootCmd.AddCommand(nsLookupCmd)
}