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


Golang Client.ExchangeRtt方法代码示例

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


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

示例1: main

func main() {
	if len(os.Args) != 2 {
		fmt.Printf("%s NAMESERVER\n", os.Args[0])
		os.Exit(1)
	}
	conf, _ := dns.ClientConfigFromFile("/etc/resolv.conf")

	m := new(dns.Msg)
	m.Question = make([]dns.Question, 1)
	c := new(dns.Client)

	addr := addresses(conf, c, os.Args[1])
	if len(addr) == 0 {
		fmt.Printf("No address found for %s\n", os.Args[1])
		os.Exit(1)
	}
	for _, a := range addr {
		m.Question[0] = dns.Question{"version.bind.", dns.TypeTXT, dns.ClassCHAOS}
		in, rtt, _ := c.ExchangeRtt(m, a)
		if in != nil && len(in.Answer) > 0 {
			fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0])
		}
		m.Question[0] = dns.Question{"hostname.bind.", dns.TypeTXT, dns.ClassCHAOS}
		in, rtt, _ = c.ExchangeRtt(m, a)
		if in != nil && len(in.Answer) > 0 {
			fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0])
		}
	}
}
开发者ID:polvi,项目名称:dns,代码行数:29,代码来源:chaos.go

示例2: main


//.........这里部分代码省略.........
				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 i, v := range qname {
		m.Question[0] = dns.Question{dns.Fqdn(v), qtype, qclass}
		m.Id = dns.Id()
		if *query {
			fmt.Printf("%s", m.String())
			fmt.Printf("\n;; size: %d bytes\n\n", m.Len())
		}
		// Add tsig
		if *tsig != "" {
			if algo, name, secret, ok := tsigKeyParse(*tsig); ok {
				m.SetTsig(name, algo, 300, time.Now().Unix())
				c.TsigSecret = map[string]string{name: secret}
			} else {
				fmt.Fprintf(os.Stderr, "TSIG key data error\n")
				return
			}
		}
		if qtype == dns.TypeAXFR {
			c.Net = "tcp"
			doXfr(c, m, nameserver)
			continue
		}
		if qtype == dns.TypeIXFR {
			doXfr(c, m, nameserver)
			continue
		}

		c.DoRtt(m, nameserver, nil, func(m, r *dns.Msg, rtt time.Duration, e error, data interface{}) {
			defer func() {
				if i == len(qname)-1 {
					os.Exit(0)
				}
			}()
		Redo:
			if e != nil {
				fmt.Printf(";; %s\n", e.Error())
				return
			}
			if r.Rcode != dns.RcodeSuccess {
				return
			}
			if r.Id != m.Id {
				fmt.Fprintf(os.Stderr, "Id mismatch\n")
				return
			}
			if r.MsgHdr.Truncated && *fallback {
				if c.Net != "tcp" {
					if !*dnssec {
						fmt.Printf(";; Truncated, trying %d bytes bufsize\n", dns.DefaultMsgSize)
						o := new(dns.RR_OPT)
						o.Hdr.Name = "."
						o.Hdr.Rrtype = dns.TypeOPT
						o.SetUDPSize(dns.DefaultMsgSize)
						m.Extra = append(m.Extra, o)
						r, rtt, e = c.ExchangeRtt(m, nameserver)
						*dnssec = true
						goto Redo
					} else {
						// First EDNS, then TCP
						fmt.Printf(";; Truncated, trying TCP\n")
						c.Net = "tcp"
						r, rtt, e = c.ExchangeRtt(m, nameserver)
						goto Redo
					}
				}
			}
			if r.MsgHdr.Truncated && !*fallback {
				fmt.Printf(";; Truncated\n")
			}
			if *check {
				sigCheck(r, nameserver, *tcp)
				nsecCheck(r)
			}
			if *short {
				r = shortMsg(r)
			}

			fmt.Printf("%v", r)
			fmt.Printf("\n;; query time: %.3d µs, server: %s(%s), size: %d bytes\n", rtt/1e3, nameserver, c.Net, r.Size)
		})
	}
	if qtype != dns.TypeAXFR && qtype != dns.TypeIXFR {
		// xfr don't start any goroutines
		select {}
	}

}
开发者ID:polvi,项目名称:dns,代码行数:101,代码来源:q.go


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