-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.go
49 lines (38 loc) · 781 Bytes
/
args.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
package main
// Helper methods used in argument parsing
import (
"net"
"regexp"
)
func validRegion(r string) bool {
match, err := regexp.MatchString("^[a-zA-Z]{3}[0-9]?$", r)
return err == nil && match
}
func validServerIP(ip string) bool {
netIP := net.ParseIP(ip)
if netIP == nil {
return false
}
ip4 := netIP.To4()
if ip4 == nil {
return false
}
lastOctal := int(ip4[3])
return netIP.IsPrivate() && lastOctal < 255
}
func validDNS(dnsServer string) bool {
netIP := net.ParseIP(dnsServer)
if netIP == nil {
return false
}
netIP.DefaultMask()
return netIP.To4() != nil
}
func clientIP(serverIP string) string {
ip := net.ParseIP(serverIP).To4()
ip[3]++
return ip.String()
}
func validPort(port int) bool {
return port >= 1 && port <= 65535
}