parent
60c66fa9ad
commit
3c00547738
|
@ -1,9 +1,9 @@
|
||||||
EXAMPLES=mx \
|
EXAMPLES=mx \
|
||||||
chaos \
|
chaos \
|
||||||
key2ds \
|
key2ds \
|
||||||
axfr
|
axfr \
|
||||||
|
q
|
||||||
# these need to be fixed
|
# these need to be fixed
|
||||||
#q \
|
|
||||||
#reflect \
|
#reflect \
|
||||||
#xfrprx \
|
#xfrprx \
|
||||||
#funkensturm
|
#funkensturm
|
||||||
|
|
129
_examples/q/q.go
129
_examples/q/q.go
|
@ -9,6 +9,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func q(w dns.RequestWriter, m *dns.Msg) {
|
||||||
|
w.Send(m)
|
||||||
|
r, _ := w.Receive()
|
||||||
|
w.Write(r)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var dnssec *bool = flag.Bool("dnssec", false, "Request DNSSEC records")
|
var dnssec *bool = flag.Bool("dnssec", false, "Request DNSSEC records")
|
||||||
var short *bool = flag.Bool("short", false, "Abbriate long DNSKEY and RRSIG RRs")
|
var short *bool = flag.Bool("short", false, "Abbriate long DNSKEY and RRSIG RRs")
|
||||||
|
@ -24,9 +30,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to think about it... Config
|
// Need to think about it... Config
|
||||||
c, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
|
conf, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
|
||||||
nameserver := "@" + c.Servers[0]
|
nameserver := "@" + conf.Servers[0]
|
||||||
qtype := uint16(dns.TypeA) // Default qtype
|
qtype := uint16(0)
|
||||||
qclass := uint16(dns.ClassINET) // Default qclass
|
qclass := uint16(dns.ClassINET) // Default qclass
|
||||||
var qname []string
|
var qname []string
|
||||||
|
|
||||||
|
@ -66,98 +72,71 @@ Flags:
|
||||||
// Anything else is a qname
|
// Anything else is a qname
|
||||||
qname = append(qname, flag.Arg(i))
|
qname = append(qname, flag.Arg(i))
|
||||||
}
|
}
|
||||||
|
if len(qname) == 0 {
|
||||||
|
qname = make([]string, 1)
|
||||||
|
qname[0] = "."
|
||||||
|
qtype = dns.TypeNS
|
||||||
|
}
|
||||||
|
if qtype == 0 {
|
||||||
|
qtype = dns.TypeA
|
||||||
|
}
|
||||||
|
|
||||||
nameserver = string([]byte(nameserver)[1:]) // chop off @
|
nameserver = string([]byte(nameserver)[1:]) // chop off @
|
||||||
if !strings.HasSuffix(nameserver, ":53") {
|
if !strings.HasSuffix(nameserver, ":53") {
|
||||||
nameserver += ":53"
|
nameserver += ":53"
|
||||||
}
|
}
|
||||||
|
// ipv6 todo
|
||||||
|
|
||||||
err := make(chan os.Error)
|
dns.HandleQueryFunc(".", q)
|
||||||
|
dns.ListenAndQuery(nil, nil)
|
||||||
|
c := dns.NewClient()
|
||||||
if *tcp {
|
if *tcp {
|
||||||
go query("tcp", err)
|
c.Net = "tcp"
|
||||||
} else {
|
|
||||||
go query("udp", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dns.InitQueryChannels()
|
|
||||||
// Start the querier in a closure
|
|
||||||
go func() {
|
|
||||||
for _, v := range qname {
|
|
||||||
d, m := newConnMsg(v, nameserver, c.Attempts, qtype, qclass, *aa, *ad, *cd, *rd, *dnssec, *nsid)
|
|
||||||
dns.QueryRequest <- &dns.Query{Query: m, Conn: d}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
i := 0
|
|
||||||
forever:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case r := <-dns.QueryReply:
|
|
||||||
if r.Reply != nil {
|
|
||||||
if r.Query.Id != r.Reply.Id {
|
|
||||||
fmt.Printf("Id mismatch\n")
|
|
||||||
}
|
|
||||||
if *short {
|
|
||||||
r.Reply = shortMsg(r.Reply)
|
|
||||||
}
|
|
||||||
fmt.Printf("%v", r.Reply)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("%v\n", r.Err.String())
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
if i == len(qname) {
|
|
||||||
break forever
|
|
||||||
}
|
|
||||||
case e := <-err:
|
|
||||||
fmt.Printf("%v", e.String())
|
|
||||||
break forever
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func query(tcp string, e chan os.Error) {
|
|
||||||
switch tcp {
|
|
||||||
case "tcp":
|
|
||||||
err := dns.QueryAndServeTCP(qhandle)
|
|
||||||
e <- err
|
|
||||||
case "udp":
|
|
||||||
err := dns.QueryAndServeUDP(qhandle)
|
|
||||||
e <- err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// reply checking 'n stuff
|
|
||||||
func qhandle(d *dns.Conn, i *dns.Msg) {
|
|
||||||
o, err := d.ExchangeMsg(i, false)
|
|
||||||
dns.QueryReply <- &dns.Query{Query: i, Reply: o, Conn: d, Err: err}
|
|
||||||
d.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func newConnMsg(qname, nameserver string, attempts int, qtype, qclass uint16, aa, ad, cd, rd, dnssec, nsid bool) (*dns.Conn, *dns.Msg) {
|
|
||||||
d := new(dns.Conn)
|
|
||||||
d.RemoteAddr = nameserver
|
|
||||||
d.Attempts = attempts
|
|
||||||
|
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.MsgHdr.Authoritative = aa
|
m.MsgHdr.Authoritative = *aa
|
||||||
m.MsgHdr.AuthenticatedData = ad
|
m.MsgHdr.AuthenticatedData = *ad
|
||||||
m.MsgHdr.CheckingDisabled = cd
|
m.MsgHdr.CheckingDisabled = *cd
|
||||||
m.MsgHdr.RecursionDesired = rd
|
m.MsgHdr.RecursionDesired = *rd
|
||||||
m.Question = make([]dns.Question, 1)
|
m.Question = make([]dns.Question, 1)
|
||||||
if dnssec || nsid {
|
if *dnssec || *nsid {
|
||||||
opt := new(dns.RR_OPT)
|
opt := new(dns.RR_OPT)
|
||||||
opt.SetDo()
|
opt.SetDo()
|
||||||
opt.SetVersion(0)
|
opt.SetVersion(0)
|
||||||
opt.SetUDPSize(dns.DefaultMsgSize)
|
opt.SetUDPSize(dns.DefaultMsgSize)
|
||||||
if nsid {
|
if *nsid {
|
||||||
opt.SetNsid("")
|
opt.SetNsid("")
|
||||||
}
|
}
|
||||||
m.Extra = make([]dns.RR, 1)
|
m.Extra = make([]dns.RR, 1)
|
||||||
m.Extra[0] = opt
|
m.Extra[0] = opt
|
||||||
}
|
}
|
||||||
m.Question[0] = dns.Question{qname, qtype, qclass}
|
for _, v := range qname {
|
||||||
m.Id = dns.Id()
|
m.Question[0] = dns.Question{v, qtype, qclass}
|
||||||
return d, m
|
m.Id = dns.Id()
|
||||||
|
c.Do(m, nameserver)
|
||||||
|
}
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
forever:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case r := <-dns.DefaultReplyChan:
|
||||||
|
if r[1] != nil {
|
||||||
|
if r[0].Id != r[1].Id {
|
||||||
|
fmt.Printf("Id mismatch\n")
|
||||||
|
}
|
||||||
|
if *short {
|
||||||
|
r[1] = shortMsg(r[1])
|
||||||
|
}
|
||||||
|
fmt.Printf("%v", r[1])
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
if i == len(qname) {
|
||||||
|
break forever
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk trough message and short Key data and Sig data
|
// Walk trough message and short Key data and Sig data
|
||||||
|
|
Loading…
Reference in New Issue