Skip to content

Instantly share code, notes, and snippets.

@miekg
Created April 15, 2011 11:18
Show Gist options
  • Save miekg/921542 to your computer and use it in GitHub Desktop.
Save miekg/921542 to your computer and use it in GitHub Desktop.
example client for async queries in Go DNS
package main
import (
"dns"
"fmt"
)
func HelloQuery(w dns.RequestWriter, req *dns.Msg, ) {
// client.Attemps = 3
// client.Retry = true // retry with TCP
// client.RemoteAddr = ":212i91"
// w.Client.Exchange(dksl) // Send to remote
w.Write(req)
}
//ListenAndQuery
func main() {
dns.HandleQueryFunc("miek.nl.", HelloQuery)
dns.ListenAndQuery(nil, nil)
m := new(dns.Msg)
m.SetQuestion("miek.nl.", dns.TypeMX)
m.MsgHdr.RecursionDesired = true
client := new(dns.Client)
client.Do(m, "127.0.0.1:53")
// rep := client.Exchange(msg, adress)
i:=0
forever:
for {
select {
case n := <-dns.DefaultReplyChan:
fmt.Printf("%v\n", n)
i++
if i == 1 {
break forever
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment