Skip to content

Instantly share code, notes, and snippets.

@miekg
Created July 11, 2012 10:18
Show Gist options
  • Save miekg/3089460 to your computer and use it in GitHub Desktop.
Save miekg/3089460 to your computer and use it in GitHub Desktop.
Create trace from zonefile
package main
import (
"github.com/miekg/dns"
"flag"
"github.com/miekg/pcap"
"os"
)
func main() {
// -o origin <file>, -t4 targetIP, -s4 srcip, -t6, -s6
m := new(dns.Msg)
for x := range dns.ParseZone(os.Stdin, "", "") {
if x.Error != nil {
println(x.Error.Error())
continue
}
if x.Error == nil {
switch t := x.RR.Header().Rrtype; t {
case dns.TypeRRSIG:
fallthrough
case dns.TypeNSEC:
fallthrough
case dns.TypeNSEC3:
continue
default:
if x.RR.Header().Name[0] == '*' { // Wildcard name
m.SetQuestion("wild" + x.RR.Header().Name[1:], t)
} else {
m.SetQuestion(x.RR.Header().Name, t)
}
if _, ok := m.Pack(); ok {
p := new(pcap.Packet)
p = p
println(m.String())
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment