This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rrdaclient.go
336 lines (290 loc) · 8.7 KB
/
rrdaclient.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
package rrdaclient
import (
"encoding/json"
"io/ioutil"
"net/http"
)
//BaseURL that points to RRDA REST API
var BaseURL = "http://api.statdns.com/"
//Question type represents the Question section in API response
type Question struct {
Name string `json: "name"`
Type string `json: "type"`
Class string `json: "class"`
}
//DNSData type represents Answer, Autority and Additional sections in API response
type DNSData struct {
Name string `json: "name"`
Type string `json: "type"`
Class string `json: "class"`
TTL int `json: "ttl"`
Rdlength int `json: "rdlength"`
Rdata string `json: "rdata"`
}
//APIResponse type represents response from RRDA API
type APIResponse struct {
Question []Question `json: "question"`
Answer []DNSData `json: "answer"`
Authority []DNSData `json: "answer"`
Additional []DNSData `json: "answer"`
}
//get data from remote url and return unparsed output
func getData(url string) ([]byte, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, nil
}
//get data from API and return APIResponse object
func getAPIResponse(url string) (*APIResponse, error) {
data, err := getData(url)
if err != nil {
return nil, err
}
var resp *APIResponse
err = json.Unmarshal(data, &resp)
if err != nil {
return nil, err
}
return resp, nil
}
/* ===== RRDA API METHODS ===== */
//GetHostAddress Get A records
//
// http://api.statdns.com/<domain>/a
func GetHostAddress(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/a"
return getAPIResponse(url)
}
//GetHostAddressV6 Get AAAA records
//
//http://api.statdns.com/statdns.net/aaaa
func GetHostAddressV6(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/aaaa"
return getAPIResponse(url)
}
//GetCertificate Get CERT records
//
//http://api.statdns.com/statdns.net/cert
func GetCertificate(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/cert"
return getAPIResponse(url)
}
//GetCanonicalName Get CNAME records
//
//http://api.statdns.com/statdns.net/cname
func GetCanonicalName(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/cname"
return getAPIResponse(url)
}
//GetDHCIDRecords Get DHCID (DHCP Identifier) records
//
//http://api.statdns.com/statdns.net/dhcid
func GetDHCIDRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/dhcid"
return getAPIResponse(url)
}
//GetDLVRecords Get DNSSEC Lookaside Validation (DLV) records
//
//http://api.statdns.com/statdns.net/dlv
func GetDLVRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/dlv"
return getAPIResponse(url)
}
//GetDNAMERecords Get Delegation name (DNAME) records
//
//http://api.statdns.com/statdns.net/dname
func GetDNAMERecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/dname"
return getAPIResponse(url)
}
//GetDNSKeyRecords Get DNS Key record (DNSKEY) records
//
//http://api.statdns.com/statdns.net/dnskey
func GetDNSKeyRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/dnskey"
return getAPIResponse(url)
}
//GetDSRecords Get Delegation Signer (DS) records
//
//http://api.statdns.com/statdns.net/ds
func GetDSRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/ds"
return getAPIResponse(url)
}
//GetHINFORecords Get Host Information (HINFO) records
//
//http://api.statdns.com/statdns.net/hinfo
func GetHINFORecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/hinfo"
return getAPIResponse(url)
}
//GetHIPRecords Get Host Identity Protocol (HIP) records
//
//http://api.statdns.com/statdns.net/hip
func GetHIPRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/hip"
return getAPIResponse(url)
}
//GetIPSECKeyRecords Get IPSec Key (IPSECKEY) records
//
//http://api.statdns.com/statdns.net/ipseckey
func GetIPSECKeyRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/ipseckey"
return getAPIResponse(url)
}
//GetKXRecords Get Key eXchanger record (KX) records
//
//http://api.statdns.com/statdns.net/kx
func GetKXRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/kx"
return getAPIResponse(url)
}
//GetLOCRecords Get Location records (LOC) records
//
//http://api.statdns.com/statdns.net/loc
func GetLOCRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/loc"
return getAPIResponse(url)
}
//GetMXRecords Get Mail Exchange record (MX) records
//
//http://api.statdns.com/statdns.net/mx
func GetMXRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/mx"
return getAPIResponse(url)
}
//GetNAPTRRecords Get Name Authority Pointer (NAPTR) records
//
//http://api.statdns.com/statdns.net/naptr
func GetNAPTRRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/naptr"
return getAPIResponse(url)
}
//GetNSRecords Get Name Servers (NS) records
//
//http://api.statdns.com/statdns.net/ns
func GetNSRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/ns"
return getAPIResponse(url)
}
//GetNSECRecords Get Next-Secure (NSEC) records
//
//http://api.statdns.com/statdns.net/nsec
func GetNSECRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/nsec"
return getAPIResponse(url)
}
//GetNSEC3Records Get NSEC record version 3 (NSEC3) records
//
//http://api.statdns.com/statdns.net/nsec3
func GetNSEC3Records(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/nsec3"
return getAPIResponse(url)
}
//GetNSEC3ParamRecords Get NSEC3 (NSEC3PARAM) records
//
//http://api.statdns.com/statdns.net/nsec3param
func GetNSEC3ParamRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/nsec3param"
return getAPIResponse(url)
}
//GetOPTRecords Get Option records OPT records
//
//http://api.statdns.com/statdns.net/opt
func GetOPTRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/opt"
return getAPIResponse(url)
}
//GetPTRRecords Get Pointer (PTR) records
//
//http://api.statdns.com/statdns.net/ptr
func GetPTRRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/ptr"
return getAPIResponse(url)
}
//GetRRSIGRecords Get Resource Records Signature (RRSIG) records
//
//http://api.statdns.com/statdns.net/rrsig
func GetRRSIGRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/rrsig"
return getAPIResponse(url)
}
//GetSOARecords Get Start of Authority (SOA) record
//
//http://api.statdns.com/statdns.net/soa
func GetSOARecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/soa"
return getAPIResponse(url)
}
//GetSPFRecords Get Sender Policy Framework (SPF) records
//
//http://api.statdns.com/statdns.net/spf
func GetSPFRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/spf"
return getAPIResponse(url)
}
//GetSRVRecords Get Service Locator (SRV) records
//
//http://api.statdns.com/statdns.net/srv
func GetSRVRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/srv"
return getAPIResponse(url)
}
//GetSSHFPRecords Get SSH Public Key Fingerprint (SSHFP) records
//
//http://api.statdns.com/statdns.net/sshfp
func GetSSHFPRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/sshfp"
return getAPIResponse(url)
}
//GetTARecords Get DNSSEC Trust Authorities (TA) records
//
//http://api.statdns.com/statdns.net/ta
func GetTARecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/ta"
return getAPIResponse(url)
}
//GetTALINKRecords Get Trust Anchor LINK (TALINK) records
//
//http://api.statdns.com/statdns.net/talink
func GetTALINKRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/talink"
return getAPIResponse(url)
}
//GetTLSARecords Get TLSA records
//
//http://api.statdns.com/_443._tcp.www.statdns.net/tlsa
func GetTLSARecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/tlsa"
return getAPIResponse(url)
}
//GetTXTRecords Get Text (TXT) records
//
//http://api.statdns.com/statdns.net/txt
func GetTXTRecords(domain string) (*APIResponse, error) {
url := BaseURL + domain + "/txt"
return getAPIResponse(url)
}
//GetReversePTRRecords Get reverse PTR record from IPv4 addresses
//
//http://api.statdns.com/x/193.0.6.139
func GetReversePTRRecords(ip string) (*APIResponse, error) {
url := BaseURL + "/x/" + ip
return getAPIResponse(url)
}
//GetReversePTRRecordsV6 Get reverse PTR record from IPv6 addresses
//
//http://api.statdns.com/x/2001:67c:2e8:22::c100:68b
func GetReversePTRRecordsV6(ip string) (*APIResponse, error) {
url := BaseURL + "/x/" + ip
return getAPIResponse(url)
}