diff --git a/cmd/geo/cmd_look.go b/cmd/geo/cmd_look.go index bc1dd99..74e4e38 100644 --- a/cmd/geo/cmd_look.go +++ b/cmd/geo/cmd_look.go @@ -93,11 +93,22 @@ func look(cmd *cobra.Command, args []string) error { if noResolve { return nil } - ips, err := net.DefaultResolver.LookupIP(context.Background(), "ip", domainName) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + + go func() { + <-ctx.Done() + fmt.Print("\n\nšŸŒŽResolved ", domainName, " timeout") + }() + + ips, err := net.DefaultResolver.LookupIP(ctx, "ip", domainName) if err != nil { fmt.Println("\n\nāŒFail to resolve", domainName, ", skipped.") } - ip = ips[0] + if len(ips) != 0 { + ip = ips[0] + } + fmt.Print("\n\nšŸŒŽResolved ", domainName, " as ", ip, "\n\n") }