-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdns.go
More file actions
40 lines (33 loc) · 636 Bytes
/
dns.go
File metadata and controls
40 lines (33 loc) · 636 Bytes
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
package ipapi
import (
"encoding/json"
"io/ioutil"
"net/http"
)
// DNS response struct
type DNS struct {
DNS struct {
IP string `json:"ip"`
Geo string `json:"geo"`
} `json:"dns"`
Edns struct {
IP string `json:"ip"`
Geo string `json:"geo"`
} `json:"edns"`
}
// GetDNS get current dns servers
func GetDNS() (DNS, error) {
resp, err := http.DefaultClient.Get("http://edns.ip-api.com/json")
if err != nil {
return DNS{}, err
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return DNS{}, err
}
var dns DNS
if err = json.Unmarshal(data, &dns); err != nil {
return dns, err
}
return dns, nil
}