1 回答

TA貢獻1812條經驗 獲得超5個贊
Go 的 LookupCNAME 函數嘗試跟蹤 CNAME 鏈直至其末尾。這意味著它認為沒有 CNAME 和 A 記錄的 DNS 名稱是錯誤的:
規范名稱是跟隨零個或多個 CNAME 記錄后的最終名稱。如果主機不包含 DNS“CNAME”記錄,只要主機解析為地址記錄,LookupCNAME 就不會返回錯誤。
Go 在標準庫中沒有提供低級 DNS API。
package main
import (
? ? "fmt"
? ? "github.com/miekg/dns"
)
func main() {
? ? config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
? ? c := new(dns.Client)
? ? m := new(dns.Msg)
? ? // Note the trailing dot. miekg/dns is very low-level and expects canonical names.
? ? m.SetQuestion("tst1crmapps.starbucks.com.", dns.TypeCNAME)
? ? m.RecursionDesired = true
? ? r, _, _ := c.Exchange(m, config.Servers[0]+":"+config.Port)
? ? fmt.Println(r.Answer[0].(*dns.CNAME).Target) // bigip-tst1crmapps-starbucks.oracle.com.
}
- 1 回答
- 0 關注
- 156 瀏覽
添加回答
舉報