2013-05-13 00:09:52 +10:00
|
|
|
// Copyright 2011 Miek Gieben. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2012-09-02 17:02:59 +10:00
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Retrieve the MX records for miek.nl.
|
2013-04-02 18:09:36 +11:00
|
|
|
func ExampleMX() {
|
2012-09-02 17:02:59 +10:00
|
|
|
config, _ := ClientConfigFromFile("/etc/resolv.conf")
|
|
|
|
c := new(Client)
|
|
|
|
m := new(Msg)
|
|
|
|
m.SetQuestion("miek.nl.", TypeMX)
|
|
|
|
m.RecursionDesired = true
|
2012-11-20 02:15:03 +11:00
|
|
|
r, _, err := c.Exchange(m, config.Servers[0]+":"+config.Port)
|
2012-09-02 17:02:59 +10:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if r.Rcode != RcodeSuccess {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, a := range r.Answer {
|
2012-12-10 05:23:25 +11:00
|
|
|
if mx, ok := a.(*MX); ok {
|
2012-09-02 17:02:59 +10:00
|
|
|
fmt.Printf("%s\n", mx.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-03 20:02:37 +10:00
|
|
|
|
|
|
|
// Retrieve the DNSKEY records of a zone and convert them
|
|
|
|
// to DS records for SHA1, SHA256 and SHA384.
|
2013-04-02 18:09:36 +11:00
|
|
|
func ExampleDS(zone string) {
|
2012-09-03 20:02:37 +10:00
|
|
|
config, _ := ClientConfigFromFile("/etc/resolv.conf")
|
|
|
|
c := new(Client)
|
|
|
|
m := new(Msg)
|
|
|
|
if zone == "" {
|
|
|
|
zone = "miek.nl"
|
|
|
|
}
|
|
|
|
m.SetQuestion(Fqdn(zone), TypeDNSKEY)
|
|
|
|
m.SetEdns0(4096, true)
|
2012-11-20 02:15:03 +11:00
|
|
|
r, _, err := c.Exchange(m, config.Servers[0]+":"+config.Port)
|
2012-09-03 20:02:37 +10:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if r.Rcode != RcodeSuccess {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, k := range r.Answer {
|
2012-12-10 05:23:25 +11:00
|
|
|
if key, ok := k.(*DNSKEY); ok {
|
2012-09-03 20:02:37 +10:00
|
|
|
for _, alg := range []int{SHA1, SHA256, SHA384} {
|
|
|
|
fmt.Printf("%s; %d\n", key.ToDS(alg).String(), key.Flags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|