-
Notifications
You must be signed in to change notification settings - Fork 2
/
dns_handlers.go
37 lines (31 loc) · 728 Bytes
/
dns_handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package dkim
import (
"errors"
"github.com/miekg/dns"
"strings"
)
func dnsFetchHandler(domain string) ([]byte, error) {
var response *dns.Msg
var txt *dns.TXT
var ok bool
var client *dns.Client = new(dns.Client)
var msg *dns.Msg = new(dns.Msg)
var err error
msg.SetQuestion(domain, dns.TypeTXT)
if response, _, err = client.Exchange(msg, dnsHost); err != nil {
return nil, err
}
for _, rr := range response.Answer {
if txt, ok = rr.(*dns.TXT); ok && len(txt.Txt) > 0 {
return []byte(strings.Join(txt.Txt, "")), nil
}
}
return nil, errors.New("not found")
}
var dnsHost string = "8.8.8.8:53"
func SetDNS(ns string) {
dnsHost = ns
}
func init() {
CustomHandlers.DnsFetchHandler = dnsFetchHandler
}