-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
dns.go
52 lines (40 loc) · 791 Bytes
/
dns.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
package utils
import (
"net"
"errors"
"strings"
// "fmt"
// "os"
)
func CheckDNS(url string) error {
Log("CheckDNS: " + url)
realHostname := GetMainConfig().HTTPConfig.Hostname
realHostname = strings.Split(realHostname, ":")[0]
ips, err := net.LookupIP(url)
ipsReal, errReal := net.LookupIP(realHostname)
if err != nil {
return err
}
if errReal != nil {
return errReal
}
ipCheck := ""
ipReal := ""
for _, ip := range ips {
// if IPV4
if ip.To4() != nil {
ipCheck = ip.String()
break
}
}
for _, ip := range ipsReal {
if ip.To4() != nil {
ipReal = ip.String()
break
}
}
if ipCheck != ipReal {
return errors.New("DNS mismatch, this endpoint does not seem to point to your server IP: " + ipCheck + " != " + ipReal)
}
return nil
}