parseIP supports IPv6
This commit is contained in:
parent
b0bb26fc95
commit
90a28e90e0
@ -152,17 +152,25 @@ func parseIP(s string, port string) (ips []string) {
|
|||||||
port = "8080" // default port
|
port = "8080" // default port
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addrFn := func(s, port string) string {
|
||||||
|
c := strings.Count(s, ":")
|
||||||
|
if c == 0 || //ipv4 or domain
|
||||||
|
s[len(s)-1] == ']' { //[ipv6]
|
||||||
|
return s + ":" + port
|
||||||
|
}
|
||||||
|
if c > 1 && s[0] != '[' { // ipv6
|
||||||
|
return "[" + s + "]:" + port
|
||||||
|
}
|
||||||
|
return s //ipv4:port or [ipv6]:port
|
||||||
|
}
|
||||||
|
|
||||||
file, err := os.Open(s)
|
file, err := os.Open(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ss := strings.Split(s, ",")
|
ss := strings.Split(s, ",")
|
||||||
for _, s := range ss {
|
for _, s := range ss {
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
if s != "" {
|
if s != "" {
|
||||||
// TODO: support IPv6
|
ips = append(ips, addrFn(s, port))
|
||||||
if !strings.Contains(s, ":") {
|
|
||||||
s = s + ":" + port
|
|
||||||
}
|
|
||||||
ips = append(ips, s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -175,10 +183,7 @@ func parseIP(s string, port string) (ips []string) {
|
|||||||
if line == "" || strings.HasPrefix(line, "#") {
|
if line == "" || strings.HasPrefix(line, "#") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !strings.Contains(line, ":") {
|
ips = append(ips, addrFn(line, port))
|
||||||
line = line + ":" + port
|
|
||||||
}
|
|
||||||
ips = append(ips, line)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user