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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
package main
import (
"bytes"
"fmt"
"github.com/miekg/dns"
"net/http"
"text/template"
"time"
)
type Zone struct {
Name string
View string
}
var SECRETS = map[string]string{
"crute-me-internal.": "",
"crute-me-external.": "",
"crute-us-internal.": "",
"crute-us-external.": "",
"crute-org-internal.": "",
"crute-org-external.": "",
"faldowski-com-internal.": "",
"faldowski-com-external.": "",
"softgroupcorp-com-internal.": "",
"softgroupcorp-com-external.": "",
}
func getValue(v interface{}) string {
switch i := v.(type) {
case *dns.SOA:
return fmt.Sprintf("%s %s %d %d %d %d %d", i.Ns, i.Mbox, i.Serial, i.Refresh, i.Retry, i.Expire, i.Minttl)
case *dns.A:
return fmt.Sprintf("%s", i.A)
case *dns.CNAME:
return fmt.Sprintf("%s", i.Target)
case *dns.AAAA:
return fmt.Sprintf("%s", i.AAAA)
case *dns.MX:
return fmt.Sprintf("%d %s", i.Preference, i.Mx)
case *dns.TXT:
b := &bytes.Buffer{}
for _, t := range i.Txt {
fmt.Fprintf(b, "\"%s\"", t) // []
}
return b.String()
case *dns.PTR:
return fmt.Sprintf("%s", i.Ptr)
case *dns.NS:
return fmt.Sprintf("%s", i.Ns)
case *dns.SRV:
return fmt.Sprintf("%d %d %d %s", i.Priority, i.Weight, i.Port, i.Target)
case *dns.SPF:
b := &bytes.Buffer{}
for _, t := range i.Txt {
fmt.Fprintf(b, "\"%s\"", t) // []
}
return b.String()
default:
return "UNKNOWN"
}
}
func getDns() chan *dns.Envelope {
c := &dns.Transfer{}
c.TsigSecret = SECRETS
m := &dns.Msg{}
m.SetAxfr("crute.me.")
m.SetTsig("crute-me-internal.", dns.HmacSHA256, 300, time.Now().Unix())
in, err := c.In(m, "172.31.46.225:53")
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return nil
}
return in
}
func dnsClass(rrh *dns.RR_Header) string {
return dns.Class(rrh.Class).String()
}
func dnsType(rrh *dns.RR_Header) string {
return dns.Type(rrh.Rrtype).String()
}
func dnsTTL(rrh *dns.RR_Header) string {
t := rrh.Ttl
if t/86400 > 1 {
return fmt.Sprintf("%d days", t/86400)
} else if t/3600 > 1 {
return fmt.Sprintf("%d hours", t/3600)
} else if t/60 > 1 {
return fmt.Sprintf("%d minutes", t/60)
} else {
return fmt.Sprintf("%d seconds", t)
}
}
func handler(w http.ResponseWriter, r *http.Request) {
fm := template.FuncMap{
"getValue": getValue,
"dnsClass": dnsClass,
"dnsType": dnsType,
"dnsTTL": dnsTTL,
}
t, _ := template.New("").Funcs(fm).ParseFiles("dns.html")
t.ExecuteTemplate(w, "dns.html", getDns())
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
|