From 2f174373e5ef09232013d3c6e77a7bd435bb2587 Mon Sep 17 00:00:00 2001 From: Kevin Wallace Date: Wed, 20 Feb 2019 01:41:05 -0800 Subject: silence "no such host" errors (strings.Contains hack because of https://github.com/golang/go/issues/28635) --- main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 7f9f8b8..af00591 100644 --- a/main.go +++ b/main.go @@ -23,14 +23,14 @@ func main() { ip := ipnet.IP for ipnet.Contains(ip) { if names, err := net.LookupAddr(ip.String()); err != nil { - fmt.Fprintf(os.Stderr, "%s\t# PTR error: %s\n", ip, err) + printErr(ip, "PTR", err) } else { fmt.Printf("%s\t%s\n", ip, strings.Join(names, " ")) } if *txt { recs, err := net.LookupTXT(arpa(ip)) if err != nil { - fmt.Fprintf(os.Stderr, "%s\t# TXT error: %s\n", ip, err) + printErr(ip, "TXT", err) } else { for _, rec := range recs { fmt.Printf("%s\tTXT %q\n", ip, rec) @@ -44,6 +44,12 @@ func main() { } } +func printErr(ip net.IP, rrtype string, err error) { + if !strings.Contains(err.Error(), "no such host") { + fmt.Fprintf(os.Stderr, "%s\t# %s error: %s\n", ip, rrtype, err) + } +} + // arpa returns the .in-addr.arpa or .ip6.arpa name corresponding with the given IP. func arpa(ip net.IP) string { if ip4 := ip.To4(); ip4 != nil { -- cgit v1.2.3