cmd/tailscale/cli: add debug command to do DNS lookups portably

To avoid dig vs nslookup vs $X availability issues between
OSes/distros. And to be in Go, to match the resolver we use.

Updates #13038

Change-Id: Ib7e5c351ed36b5470a42cbc230b8f27eed9a1bf8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/7427/head
Brad Fitzpatrick 3 months ago committed by Brad Fitzpatrick
parent 8e42510a71
commit 690d3bfafe

@ -319,6 +319,17 @@ var debugCmd = &ffcli.Command{
return fs return fs
})(), })(),
}, },
{
Name: "resolve",
ShortUsage: "tailscale debug resolve <hostname>",
Exec: runDebugResolve,
ShortHelp: "Does a DNS lookup",
FlagSet: (func() *flag.FlagSet {
fs := newFlagSet("resolve")
fs.StringVar(&resolveArgs.net, "net", "ip", "network type to resolve (ip, ip4, ip6)")
return fs
})(),
},
}, },
} }
@ -1167,3 +1178,26 @@ func runDebugDialTypes(ctx context.Context, args []string) error {
fmt.Printf("%s", body) fmt.Printf("%s", body)
return nil return nil
} }
var resolveArgs struct {
net string // "ip", "ip4", "ip6""
}
func runDebugResolve(ctx context.Context, args []string) error {
if len(args) != 1 {
return errors.New("usage: tailscale debug resolve <hostname>")
}
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
host := args[0]
ips, err := net.DefaultResolver.LookupIP(ctx, resolveArgs.net, host)
if err != nil {
return err
}
for _, ip := range ips {
fmt.Printf("%s\n", ip)
}
return nil
}

Loading…
Cancel
Save