github.com/zartbot/goflow@v0.0.0-20221001080520-456f7dfad288/service/identity/dnsptr.go (about) 1 package identity 2 3 import ( 4 "bytes" 5 "net" 6 "strings" 7 "time" 8 ) 9 10 func LookupDNSAddr(ipaddr string, ptrLookUp bool) (map[string]interface{}, int) { 11 var result = make(map[string]interface{}) 12 result["hostType"] = "DNS/SSL" 13 var resulttype int = 0 14 vA, ok := Service["DNS"].Load(ipaddr) 15 if ok { 16 result["Name"] = vA.(string) 17 resulttype = 1 18 } else if ptrLookUp { 19 rA, _ := net.LookupAddr(ipaddr) 20 var buf bytes.Buffer 21 for _, item := range rA { 22 if len(item) > 0 { 23 //some platform may add dot in suffix 24 item = strings.TrimSuffix(item, ".") 25 if !strings.HasSuffix(item, ".in-addr.arpa") { 26 buf.WriteString(item) 27 } 28 } 29 } 30 dnsstr := buf.String() 31 result["HostName"] = dnsstr 32 resulttype = 1 33 //store to cache 34 Service["DNS"].Store(ipaddr, dnsstr, time.Now()) 35 } 36 return result, resulttype 37 }