forked from nkeonkeo/MediaUnlockTest
-
Notifications
You must be signed in to change notification settings - Fork 8
/
NLZIET.go
executable file
·47 lines (43 loc) · 1.03 KB
/
NLZIET.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
package mediaunlocktest
import (
"io"
"net/http"
"strings"
)
func SupportNLZIET(loc string) bool {
var NLZIET_SUPPORT_COUNTRY = []string{
"BE", "BG", "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "HR", "IT", "CY", "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO", "SI", "SK", "FI", "SE",
}
for _, s := range NLZIET_SUPPORT_COUNTRY {
if loc == s {
return true
}
}
return false
}
func NLZIET(c http.Client) Result {
resp, err := GET(c, "https://nlziet.nl/cdn-cgi/trace")
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
s := string(b)
i := strings.Index(s, "loc=")
if i == -1 {
return Result{Status: StatusUnexpected}
}
s = s[i+4:]
i = strings.Index(s, "\n")
if i == -1 {
return Result{Status: StatusUnexpected}
}
loc := s[:i]
if SupportNLZIET(loc) {
return Result{Status: StatusOK, Region: strings.ToLower(loc)}
}
return Result{Status: StatusNo}
}