-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnsoverhttps.go
More file actions
78 lines (64 loc) · 1.47 KB
/
Copy pathdnsoverhttps.go
File metadata and controls
78 lines (64 loc) · 1.47 KB
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
package dnsoverhttps
import (
"fmt"
//"io/ioutil"
"log"
"net/http"
"encoding/json"
)
var (
baseurl = "https://dns.google.com/"
resolve = "resolve"
)
type DNSResponse struct {
Status int32 `json:"Status"`
TC bool `json:"TC"`
RD bool `json:"RD"`
RA bool `json:"RA"`
AD bool `json:"AD"`
CD bool `json:"CD"`
Question []Question `json:"Question"`
Answer []Answer `json:"Answer"`
Additional []Additional `json:"Additional"`
edns_client_subnet string `json:"edns_client_subnet"`
Comment string `json:"Comment"`
}
type Question struct {
Name string `json:"name"`
TypeId int32 `json:"type"`
}
type Answer struct {
Name string `json:"name"`
TypeId int32 `json:"type"`
TTL int32 `json:"TTL"`
Data string `json:"data"`
}
type Additional struct {
Unknown string
}
// Call the API request
func Call(url string) {
log.Printf("http.Get: %s", url)
res, err := http.Get(url)
if err != nil {
panic(err)
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
var data DNSResponse
err = decoder.Decode(&data)
if err != nil {
panic(err)
}
for i, answer := range data.Answer{
fmt.Printf("%d: %#v %#v\n", i, answer.Data, answer.Name)
}
fmt.Printf("%+v\n", data)
}
// A record query
func A(address string) (string, error) {
log.Printf("Resolving A: %s", address)
query := "https://dns.google.com/resolve?name=" + address
Call(query)
return "", nil
}