Skip to content

Instantly share code, notes, and snippets.

@miekg
Created July 9, 2012 08:49
Show Gist options
  • Save miekg/3075199 to your computer and use it in GitHub Desktop.
Save miekg/3075199 to your computer and use it in GitHub Desktop.
check DS
package main
import (
"flag"
"fmt"
"github.com/miekg/dns"
"os"
"unbound"
)
func main() {
u := unbound.New()
defer u.Destroy()
flag.Parse()
if err := setupUnbound(u); err != nil {
fmt.Printf("error %s\n", err.Error())
os.Exit(1)
}
// As for NS, so we can use these later on
r, err := u.Resolve(flag.Arg(0), dns.TypeNS, dns.ClassINET)
if err != nil {
fmt.Printf("error %s\n", err.Error())
os.Exit(1)
}
if r.HaveData {
if r.Secure {
fmt.Printf("Result is secure\n")
} else if r.Bogus {
fmt.Printf("Result is bogus: %s\n", r.WhyBogus)
} else {
fmt.Printf("Result is insecure\n")
}
} else {
println("NO DATA")
os.Exit(1)
}
u1 := unbound.New()
setupUnbound(u1)
if err := u1.AddTaFile(flag.Arg(1)); err != nil {
println(err.Error())
}
r, err = u1.Resolve(flag.Arg(0), dns.TypeNS, dns.ClassINET)
if err != nil {
fmt.Printf("error %s\n", err.Error())
os.Exit(1)
}
if r.HaveData {
if r.Secure {
fmt.Printf("Result is secure\n")
} else if r.Bogus {
fmt.Printf("Result is bogus: %s\n", r.WhyBogus)
} else {
fmt.Printf("Result is insecure\n")
}
} else {
println("NO DATA")
os.Exit(1)
}
}
func setupUnbound(u *unbound.Unbound) error {
if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
return err
}
if err := u.AddTaFile("Kroot.key"); err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment