Skip to content

Instantly share code, notes, and snippets.

@mischief
Created July 13, 2018 14:00
Show Gist options
  • Save mischief/8b8f6b1b206de8c97b6911a1c0a7c740 to your computer and use it in GitHub Desktop.
Save mischief/8b8f6b1b206de8c97b6911a1c0a7c740 to your computer and use it in GitHub Desktop.
quick and dirty test dns server with different negative rcodes
package main
import (
"fmt"
"github.com/miekg/dns"
)
func negrcode(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.Authoritative = true
fmt.Printf("QUESTION\n%+v\n", r)
switch r.Question[0].Qtype {
case dns.TypeAAAA:
m.SetRcode(r, dns.RcodeYXDomain)
case dns.TypeA:
m.SetRcode(r, dns.RcodeNotZone)
case dns.TypeCNAME:
m.SetRcode(r, dns.RcodeNotAuth)
default:
m.SetRcode(r, dns.RcodeNotImplemented)
}
fmt.Printf("REPLY\n%+v\n", m)
if err := w.WriteMsg(m); err != nil {
fmt.Printf("REPLY ERROR: %v\n", err)
}
}
func main() {
dns.HandleFunc("home.arpa.", negrcode)
server := &dns.Server{Addr: "[::]:53", Net: "udp", TsigSecret: nil}
if err := server.ListenAndServe(); err != nil {
fmt.Printf("Failed to setup the udp server: %s\n", err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment