aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Wallace <doof@doof.net>2019-02-20 01:41:05 -0800
committerKevin Wallace <doof@doof.net>2019-02-20 01:41:11 -0800
commit2f174373e5ef09232013d3c6e77a7bd435bb2587 (patch)
tree98868721d95f9b109ac0045a17e6b1d24637d008
parentadd -txt flag to also look up TXT records (diff)
silence "no such host" errors
(strings.Contains hack because of https://github.com/golang/go/issues/28635)
-rw-r--r--main.go10
1 files 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 {