Add axfr/ixfr support to q
This commit is contained in:
parent
ec1f57db6c
commit
13a1e4a4ae
|
@ -1,46 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/miekg/dns"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
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(dns.Fqdn(zone), uint32(*serial))
|
||||
} else {
|
||||
m.SetAxfr(dns.Fqdn(zone))
|
||||
}
|
||||
if *tsig != "" {
|
||||
a := strings.SplitN(*tsig, ":", 2)
|
||||
name, secret := a[0], a[1]
|
||||
client.TsigSecret = map[string]string{dns.Fqdn(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 {
|
||||
for _, rr := range r.RR {
|
||||
fmt.Printf("%v\n", rr)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("error: %s\n", r.Error.Error())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Error %v\n", e)
|
||||
}
|
||||
}
|
14
ex/q/q.go
14
ex/q/q.go
|
@ -187,7 +187,12 @@ Flags:
|
|||
return
|
||||
}
|
||||
}
|
||||
if qtype == dns.TypeAXFR || qtype == dns.TypeIXFR {
|
||||
if qtype == dns.TypeAXFR {
|
||||
c.Net = "tcp"
|
||||
doXfr(c, m, nameserver)
|
||||
continue
|
||||
}
|
||||
if qtype == dns.TypeIXFR {
|
||||
doXfr(c, m, nameserver)
|
||||
continue
|
||||
}
|
||||
|
@ -246,7 +251,10 @@ Flags:
|
|||
fmt.Printf("\n;; query time: %.3d µs, server: %s(%s), size: %d bytes\n", rtt/1e3, nameserver, c.Net, r.Size)
|
||||
})
|
||||
}
|
||||
select {}
|
||||
if qtype != dns.TypeAXFR && qtype != dns.TypeIXFR {
|
||||
// xfr don't start any goroutines
|
||||
select {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -425,6 +433,6 @@ func doXfr(c *dns.Client, m *dns.Msg, nameserver string) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Error %v\n", e)
|
||||
fmt.Fprintf(os.Stderr, "Failure to read XFR: %s\n", e.Error())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue