I'm looking for a way (in Go) to get the CNAME (if any) of a given host, whether that host's DNS resolution fails or not.
The DNS resolution of a host may fail and yield NXDOMAIN
, but the host in question may still have a CNAME record. At the time of writing this question, tst1crmapps.starbucks.com
is an example of such a host:
$ dig tst1crmapps.starbucks.com | grep -E 'NXDOMAIN|CNAME'
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 50444
tst1crmapps.starbucks.com. 86400 IN CNAME bigip-tst1crmapps-starbucks.oracle.com.
(run on macOS)
Function net.LookupCNAME
seems to be right up my alley, but it fails to return the CNAME if the host's DNS resolution fails. Running
package main
import (
"log"
"net"
)
func main() {
cname, err := net.LookupCNAME("tst1crmapps.starbucks.com")
if err != nil {
log.Fatal(err)
}
log.Println(cname)
}
yields
yyyy/MM/dd hh:mm:ss lookup tst1crmapps.starbucks.com: no such host
Am I misunderstanding net.LookupCNAME
? Or am I using the wrong function?