Created
April 15, 2011 11:18
-
-
Save miekg/921542 to your computer and use it in GitHub Desktop.
example client for async queries in Go DNS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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