本文整理汇总了Golang中dns.Msg.SetQuestion方法的典型用法代码示例。如果您正苦于以下问题:Golang Msg.SetQuestion方法的具体用法?Golang Msg.SetQuestion怎么用?Golang Msg.SetQuestion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dns.Msg
的用法示例。
在下文中一共展示了Msg.SetQuestion方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
if len(os.Args) != 2 || err != nil {
fmt.Printf("%s DOMAIN\n", os.Args[0])
os.Exit(1)
}
m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeDNSKEY)
m.SetEdns0(2048, true)
c := new(dns.Client)
r, _ := c.Exchange(m, conf.Servers[0]+":"+conf.Port)
if r == nil {
fmt.Printf("*** no answer received for %s\n", os.Args[1])
os.Exit(1)
}
if r.Rcode != dns.RcodeSuccess {
fmt.Printf(" *** invalid answer name %s after DNSKEY query for %s\n", os.Args[1], os.Args[1])
os.Exit(1)
}
for _, k := range r.Answer {
if key, ok := k.(*dns.RR_DNSKEY); ok {
key.Hdr.Ttl = 0
for _, alg := range []int{dns.SHA1, dns.SHA256, dns.SHA384} {
ds := key.ToDS(alg)
fmt.Printf("%v; %d\n", ds, key.Flags)
}
}
}
}
示例2: 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
}
示例3: main
func main() {
if len(os.Args) != 2 {
fmt.Printf("%s DOMAIN\n", os.Args[0])
os.Exit(1)
}
// Error checking
config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
c := dns.NewClient()
m := new(dns.Msg)
m.SetQuestion(os.Args[1], dns.TypeMX)
m.MsgHdr.RecursionDesired = true
// Simple sync query, nothing fancy
r := c.Exchange(m, config.Servers[0])
if r == nil {
os.Exit(1)
}
if r.Rcode != dns.RcodeSuccess {
fmt.Printf(" *** invalid answer name %s after MX query for %s\n", os.Args[1], os.Args[1])
os.Exit(1)
}
// Stuff must be in the answer section
for _, a := range r.Answer {
fmt.Printf("%v\n", a)
}
}
示例4: main
func main() {
conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
if len(os.Args) != 2 || err != nil {
fmt.Printf("%s DOMAIN\n", os.Args[0])
os.Exit(1)
}
m := new(dns.Msg)
m.SetQuestion(os.Args[1], dns.TypeDNSKEY)
// Set EDNS0's Do bit
e := new(dns.RR_OPT)
e.Hdr.Name = "."
e.Hdr.Rrtype = dns.TypeOPT
e.SetUDPSize(2048)
e.SetDo()
m.Extra = append(m.Extra, e)
c := dns.NewClient()
r := c.Exchange(m, conf.Servers[0])
if r == nil {
fmt.Printf("*** no answer received for %s\n", os.Args[1])
os.Exit(1)
}
if r.Rcode != dns.RcodeSuccess {
fmt.Printf(" *** invalid answer name %s after DNSKEY query for %s\n", os.Args[1], os.Args[1])
os.Exit(1)
}
// Stuff must be in the answer section, check len(r.Answer)
for _, k := range r.Answer {
// Foreach key would need to provide a DS records, both sha1 and sha256
if key, ok := k.(*dns.RR_DNSKEY); ok {
key.Hdr.Ttl = 0
ds := key.ToDS(dns.SHA1)
fmt.Printf("%v\n", ds)
ds = key.ToDS(dns.SHA256)
fmt.Printf("%v\n", ds)
ds = key.ToDS(dns.SHA384)
fmt.Printf("%v\n", ds)
}
}
}
示例5: 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 := dns.NewClient()
if tcp {
c.Net = "tcp"
}
m := new(dns.Msg)
m.SetQuestion(name, dns.TypeDNSKEY)
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
}
示例6: 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
}