当前位置: 首页>>代码示例>>Golang>>正文


Golang ClientConfig.Search方法代码示例

本文整理汇总了Golang中github.com/miekg/dns.ClientConfig.Search方法的典型用法代码示例。如果您正苦于以下问题:Golang ClientConfig.Search方法的具体用法?Golang ClientConfig.Search怎么用?Golang ClientConfig.Search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/miekg/dns.ClientConfig的用法示例。


在下文中一共展示了ClientConfig.Search方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

/*
Cname:src.iduwpui.qiniudns.com.	572	IN	CNAME	nb-gate-io-src.qiniu.com.
A:nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.5
A:nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.23
A:nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.6
A:nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.7
A:nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.8
A:nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.21
;; opcode: QUERY, status: NOERROR, id: 30362
;; flags: qr ra; QUERY: 1, ANSWER: 7, AUTHORITY: 2, ADDITIONAL: 12

;; QUESTION SECTION:
;src.iduwpui.qiniudns.com.	IN	 A

;; ANSWER SECTION:
src.iduwpui.qiniudns.com.	572	IN	CNAME	nb-gate-io-src.qiniu.com.
nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.5
nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.23
nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.6
nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.7
nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.8
nb-gate-io-src.qiniu.com.	171	IN	A	101.71.123.21

;; AUTHORITY SECTION:
qiniu.com.	30674	IN	NS	ns3.dnsv5.com.
qiniu.com.	30674	IN	NS	ns4.dnsv5.com.

;; ADDITIONAL SECTION:
ns3.dnsv5.com.	95697	IN	A	121.51.2.171
ns3.dnsv5.com.	95697	IN	A	125.39.213.190
ns3.dnsv5.com.	95697	IN	A	180.153.10.169
ns3.dnsv5.com.	95697	IN	A	182.140.167.191
ns3.dnsv5.com.	95697	IN	A	183.60.57.192
ns3.dnsv5.com.	95697	IN	A	183.60.59.217
ns3.dnsv5.com.	95697	IN	A	184.105.206.63
ns3.dnsv5.com.	95697	IN	A	112.90.143.36
ns3.dnsv5.com.	95697	IN	A	115.236.151.180
ns3.dnsv5.com.	95697	IN	A	117.135.170.109
ns3.dnsv5.com.	95697	IN	A	119.28.48.224
ns3.dnsv5.com.	95697	IN	A	119.167.195.9

*/
func main() {
	config := new(dns.ClientConfig)
	config.Servers = make([]string, 0)
	config.Search = make([]string, 0)
	config.Port = "53"
	config.Ndots = 1
	config.Timeout = 5
	config.Attempts = 2
	//    localdns := "127.0.0.1"
	localdns := "202.96.64.68"
	//localdns := "114.114.114.114"
	config.Servers = append(config.Servers, localdns)

	c := &dns.Client{
		DialTimeout: time.Second,
	}

	// query := "www.a.shifen.com."
	query := "src.iduwpui.qiniudns.com"

	m := new(dns.Msg)
	m.SetQuestion(dns.Fqdn(query), dns.TypeA)
	m.RecursionDesired = false

	r, _, err := c.Exchange(m, net.JoinHostPort(config.Servers[0], config.Port))
	if r == nil {
		log.Fatalf("*** error: %s\n", err.Error())
	}

	if r.Rcode != dns.RcodeSuccess {
		log.Fatalf(" *** invalid answer name %s after MX query for %s\n", query, query)
	}
	// Stuff must be in the answer section
	for _, a := range r.Answer {
		if a.Header().Rrtype == dns.TypeA {
			fmt.Printf("A:%v\n", a)
		} else {
			fmt.Printf("Cname:%v\n", a)
		}
	}

	fmt.Println(r.String())
}
开发者ID:gaolichuang,项目名称:code-tutorial-go,代码行数:85,代码来源:dns-client.go


注:本文中的github.com/miekg/dns.ClientConfig.Search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。