本文整理汇总了Golang中dns.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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)
}
}
}
}
示例3: 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])
}
}
}
示例4: 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
}
示例5: probe
// probe creates a packet and sends it to the nameserver. It
// returns a fingerprint.
func probe(c *dns.Client, addr string, f *fingerprint) *fingerprint {
m := f.msg()
r, err := c.Exchange(m, addr)
if err != nil {
return errorToFingerprint(err)
}
return toFingerprint(r)
}
示例6: 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
}
示例7: 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
}
示例8: main
func main() {
dnssec := flag.Bool("dnssec", false, "request DNSSEC records")
query := flag.Bool("question", false, "show question")
short := flag.Bool("short", false, "abbreviate long DNSSEC records")
check := flag.Bool("check", false, "check internal DNSSEC consistency")
six := flag.Bool("6", false, "use IPv6 only")
four := flag.Bool("4", false, "use IPv4 only")
anchor := flag.String("anchor", "", "use the DNSKEY in this file for interal DNSSEC consistency")
tsig := flag.String("tsig", "", "request tsig with key: [hmac:]name:key")
port := flag.Int("port", 53, "port number to use")
aa := flag.Bool("aa", false, "set AA flag in query")
ad := flag.Bool("ad", false, "set AD flag in query")
cd := flag.Bool("cd", false, "set CD flag in query")
rd := flag.Bool("rd", true, "set RD flag in query")
fallback := flag.Bool("fallback", false, "fallback to 4096 bytes bufsize and after that TCP")
tcp := flag.Bool("tcp", false, "TCP mode")
nsid := flag.Bool("nsid", false, "set edns nsid option")
client := flag.String("client", "", "set edns client-subnet option")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [@server] [qtype] [qclass] [name ...]\n", os.Args[0])
flag.PrintDefaults()
}
conf, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
nameserver := "@" + conf.Servers[0]
qtype := uint16(0)
qclass := uint16(dns.ClassINET) // Default qclass
var qname []string
flag.Parse()
if *anchor != "" {
f, err := os.Open(*anchor)
if err != nil {
fmt.Fprintf(os.Stderr, "Failure to open %s: %s\n", *anchor, err.Error())
}
r, err := dns.ReadRR(f, *anchor)
if err != nil {
fmt.Fprintf(os.Stderr, "Failure to read an RR from %s: %s\n", *anchor, err.Error())
}
if k, ok := r.(*dns.RR_DNSKEY); !ok {
fmt.Fprintf(os.Stderr, "No DNSKEY read from %s\n", *anchor)
} else {
dnskey = k
}
}
Flags:
for i := 0; i < flag.NArg(); i++ {
// If it starts with @ it is a nameserver
if flag.Arg(i)[0] == '@' {
nameserver = flag.Arg(i)
continue Flags
}
// First class, then type, to make ANY queries possible
// And if it looks like type, it is a type
if k, ok := dns.Str_rr[strings.ToUpper(flag.Arg(i))]; ok {
qtype = k
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
}
// If it looks like a class, it is a class
if k, ok := dns.Str_class[strings.ToUpper(flag.Arg(i))]; ok {
qclass = k
continue Flags
}
// If it starts with TYPExxx it is unknown rr
if strings.HasPrefix(flag.Arg(i), "TYPE") {
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
}
//.........这里部分代码省略.........
示例9: main
func main() {
dnssec := flag.Bool("dnssec", false, "request DNSSEC records")
query := flag.Bool("question", false, "show question")
short := flag.Bool("short", false, "abbreviate long DNSSEC records")
check := flag.Bool("check", false, "check internal DNSSEC consistency")
six := flag.Bool("6", false, "use IPv6 only")
four := flag.Bool("4", false, "use IPv4 only")
anchor := flag.String("anchor", "", "use the DNSKEY in this file for interal DNSSEC consistency")
tsig := flag.String("tsig", "", "request tsig with key: [hmac:]name:key")
port := flag.Int("port", 53, "port number to use")
aa := flag.Bool("aa", false, "set AA flag in query")
ad := flag.Bool("ad", false, "set AD flag in query")
cd := flag.Bool("cd", false, "set CD flag in query")
rd := flag.Bool("rd", true, "set RD flag in query")
fallback := flag.Bool("fallback", false, "fallback to 4096 bytes bufsize and after that TCP")
tcp := flag.Bool("tcp", false, "TCP mode")
nsid := flag.Bool("nsid", false, "ask for NSID")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [@server] [qtype] [qclass] [name ...]\n", os.Args[0])
flag.PrintDefaults()
}
conf, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
nameserver := "@" + conf.Servers[0]
qtype := uint16(0)
qclass := uint16(dns.ClassINET) // Default qclass
var qname []string
flag.Parse()
if *anchor != "" {
f, err := os.Open(*anchor)
if err != nil {
fmt.Fprintf(os.Stderr, "Failure to open %s: %s\n", *anchor, err.Error())
}
r, err := dns.ReadRR(f, *anchor)
if err != nil {
fmt.Fprintf(os.Stderr, "Failure to read an RR from %s: %s\n", *anchor, err.Error())
}
if k, ok := r.(*dns.RR_DNSKEY); !ok {
fmt.Fprintf(os.Stderr, "No DNSKEY read from %s\n", *anchor)
} else {
dnskey = k
}
}
Flags:
for i := 0; i < flag.NArg(); i++ {
// If it starts with @ it is a nameserver
if flag.Arg(i)[0] == '@' {
nameserver = flag.Arg(i)
continue Flags
}
// First class, then type, to make ANY queries possible
// And if it looks like type, it is a type
if k, ok := dns.Str_rr[strings.ToUpper(flag.Arg(i))]; ok {
qtype = k
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
}
// If it looks like a class, it is a class
if k, ok := dns.Str_class[strings.ToUpper(flag.Arg(i))]; ok {
qclass = k
continue Flags
}
// If it starts with TYPExxx it is unknown rr
if strings.HasPrefix(flag.Arg(i), "TYPE") {
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
}
//.........这里部分代码省略.........