本文整理汇总了Golang中dns.Client.Net方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Net方法的具体用法?Golang Client.Net怎么用?Golang Client.Net使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dns.Client
的用法示例。
在下文中一共展示了Client.Net方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
serial := flag.Int("serial", 0, "Perform an IXFR with the given serial")
nameserver := flag.String("ns", "127.0.0.1:53", "Query this nameserver")
tsig := flag.String("tsig", "", "request tsig with key: name:key (only hmac-md5)")
flag.Parse()
zone := flag.Arg(flag.NArg() - 1)
client := new(dns.Client)
client.Net = "tcp"
m := new(dns.Msg)
if *serial > 0 {
m.SetIxfr(zone, uint32(*serial))
} else {
m.SetAxfr(zone)
}
if *tsig != "" {
a := strings.SplitN(*tsig, ":", 2)
name, secret := a[0], a[1]
client.TsigSecret = map[string]string{name: secret}
m.SetTsig(name, dns.HmacMD5, 300, time.Now().Unix())
}
if t, e := client.XfrReceive(m, *nameserver); e == nil {
for r := range t {
if r.Error == nil {
fmt.Printf("%v\n", r.Reply)
}
}
} else {
fmt.Printf("Error %v\n", e)
}
}
示例2: getKey
// Get the key from the DNS (uses the local resolver) and return them.
// If nothing is found we return nil
func getKey(name string, keytag uint16, server string, tcp bool) *dns.RR_DNSKEY {
c := new(dns.Client)
if tcp {
c.Net = "tcp"
}
m := new(dns.Msg)
m.SetQuestion(name, dns.TypeDNSKEY)
m.SetEdns0(4096, true)
r, err := c.Exchange(m, server)
if err != nil {
return nil
}
for _, k := range r.Answer {
if k1, ok := k.(*dns.RR_DNSKEY); ok {
if k1.KeyTag() == keytag {
return k1
}
}
}
return nil
}
示例3: main
//.........这里部分代码省略.........
i, e := strconv.Atoi(string([]byte(flag.Arg(i))[4:]))
if e == nil {
qtype = uint16(i)
switch qtype {
case dns.TypeAXFR:
fmt.Fprintf(os.Stderr, "AXFR not supported\n")
return
case dns.TypeIXFR:
fmt.Fprintf(os.Stderr, "AXFR not supported\n")
return
}
continue Flags
}
}
// Anything else is a qname
qname = append(qname, flag.Arg(i))
}
if len(qname) == 0 {
qname = make([]string, 1)
qname[0] = "."
qtype = dns.TypeNS
}
if qtype == 0 {
qtype = dns.TypeA
}
nameserver = string([]byte(nameserver)[1:]) // chop off @
nameserver += ":" + strconv.Itoa(*port)
// We use the async query handling, just to show how it is to be used.
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 {
示例4: main
//.........这里部分代码省略.........
qtype = uint16(i)
switch qtype {
case dns.TypeAXFR:
fmt.Fprintf(os.Stderr, "AXFR not supported\n")
return
case dns.TypeIXFR:
fmt.Fprintf(os.Stderr, "AXFR not supported\n")
return
}
continue Flags
}
}
// Anything else is a qname
qname = append(qname, flag.Arg(i))
}
if len(qname) == 0 {
qname = make([]string, 1)
qname[0] = "."
qtype = dns.TypeNS
}
if qtype == 0 {
qtype = dns.TypeA
}
nameserver = string([]byte(nameserver)[1:]) // chop off @
nameserver += ":" + strconv.Itoa(*port)
// We use the async query handling, just to show how it is to be used.
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 {
o := new(dns.RR_OPT)
o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT
if *dnssec {
o.SetDo()
o.SetUDPSize(dns.DefaultMsgSize)
}
if *nsid {
o.SetNsid("")