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


Golang Client.Do方法代码示例

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


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

示例1: addresses

func addresses(conf *dns.ClientConfig, c *dns.Client, name string) []string {
	m4 := new(dns.Msg)
	m4.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeA)
	m6 := new(dns.Msg)
	m6.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeAAAA)

	addr := make(chan []string)
	defer close(addr)
	c.Do(m4, conf.Servers[0]+":"+conf.Port, addr, qhandler)
	c.Do(m6, conf.Servers[0]+":"+conf.Port, addr, qhandler)

	var ips []string
	i := 2 // two outstanding queries
forever:
	for {
		select {
		case ip := <-addr:
			ips = append(ips, ip...)
			i--
			if i == 0 {
				break forever
			}
		}
	}
	return ips
}
开发者ID:wallrat,项目名称:dns,代码行数:26,代码来源:chaos.go

示例2: addresses

func addresses(conf *dns.ClientConfig, c *dns.Client, name string) []string {
	dns.HandleQueryFunc(os.Args[1], qhandler)
	dns.ListenAndQuery(nil, nil)

	m4 := new(dns.Msg)
	m4.SetQuestion(os.Args[1], dns.TypeA)
	m6 := new(dns.Msg)
	m6.SetQuestion(os.Args[1], dns.TypeAAAA)
	c.Do(m4, conf.Servers[0]) // Also 1 and 2 (and merge the results??
	c.Do(m6, conf.Servers[0])

	var ips []string
	i := 2 // two outstanding queries
forever:
	for {
		select {
		case r := <-dns.DefaultReplyChan:
			if r[1] != nil && r[1].Rcode == dns.RcodeSuccess {
				for _, aa := range r[1].Answer {
					switch aa.(type) {
					case *dns.RR_A:
						ips = append(ips, aa.(*dns.RR_A).A.String()+":53")
					case *dns.RR_AAAA:
						ips = append(ips, "["+aa.(*dns.RR_AAAA).AAAA.String()+"]:53")
					}
				}
			} else {
				fmt.Printf("Nothing recevied for %s\n", name)
			}
			i--
			if i == 0 {
				break forever
			}
		}
	}
	return ips
}
开发者ID:andradeandrey,项目名称:godns,代码行数:37,代码来源:chaos.go

示例3: main


//.........这里部分代码省略.........
	dns.HandleQuery(".", q)
	dns.ListenAndQuery(nil)
	c := new(dns.Client)
	if *tcp {
		c.Net = "tcp"
		if *four {
			c.Net = "tcp4"
		}
		if *six {
			c.Net = "tcp6"
		}
	} else {
		c.Net = "udp"
		if *four {
			c.Net = "udp4"
		}
		if *six {
			c.Net = "udp6"
		}
	}

	m := new(dns.Msg)
	m.MsgHdr.Authoritative = *aa
	m.MsgHdr.AuthenticatedData = *ad
	m.MsgHdr.CheckingDisabled = *cd
	m.MsgHdr.RecursionDesired = *rd
	m.Question = make([]dns.Question, 1)

	if *dnssec || *nsid || *client != "" {
		o := new(dns.RR_OPT)
		o.Hdr.Name = "."
		o.Hdr.Rrtype = dns.TypeOPT
		if *dnssec {
			o.SetDo()
			o.SetUDPSize(dns.DefaultMsgSize)
		}
		if *nsid {
			e := new(dns.EDNS0_NSID)
			e.Code = dns.EDNS0NSID
			o.Option = append(o.Option, e)
			// NSD will not return nsid when the udp message size is too small
			o.SetUDPSize(dns.DefaultMsgSize)
		}
		if *client != "" {
			e := new(dns.EDNS0_SUBNET)
			e.Code = dns.EDNS0SUBNET
			e.SourceScope = 0
			e.Address = net.ParseIP(*client)
			if e.Address == nil {
				fmt.Fprintf(os.Stderr, "Failure to parse IP address: %s\n", *client)
				return
			}
			e.Family = 1 // IP4
			e.SourceNetmask = net.IPv4len * 8
			if e.Address.To4() == nil {
				e.Family = 2 // IP6
				e.SourceNetmask = net.IPv6len * 8
			}
			o.Option = append(o.Option, e)
		}
		m.Extra = append(m.Extra, o)
	}

	for _, v := range qname {
		m.Question[0] = dns.Question{v, qtype, qclass}
		m.Id = dns.Id()
开发者ID:ikbear,项目名称:dns,代码行数:67,代码来源:q.go


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