improve: use IndexByte to find the colon of ip address (#92)
This commit is contained in:
parent
ee37e35eb2
commit
88efe2d1d5
@ -575,7 +575,7 @@ func handleTcpPingTask(task *pb.Task, result *pb.TaskResult) {
|
|||||||
result.Data = err.Error()
|
result.Data = err.Error()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if strings.Contains(ipAddr, ":") {
|
if strings.IndexByte(ipAddr, ':') != -1 {
|
||||||
ipAddr = fmt.Sprintf("[%s]", ipAddr)
|
ipAddr = fmt.Sprintf("[%s]", ipAddr)
|
||||||
}
|
}
|
||||||
printf("TCP-Ping Task: Pinging %s:%s", ipAddr, port)
|
printf("TCP-Ping Task: Pinging %s:%s", ipAddr, port)
|
||||||
|
@ -91,11 +91,11 @@ func fetchIP(servers []string, isV6 bool) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 没取到 v6 IP
|
// 没取到 v6 IP
|
||||||
if isV6 && !strings.Contains(newIP, ":") {
|
if isV6 && strings.IndexByte(newIP, ':') == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// 没取到 v4 IP
|
// 没取到 v4 IP
|
||||||
if !isV6 && !strings.Contains(newIP, ".") {
|
if !isV6 && strings.IndexByte(newIP, '.') == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ip = newIP
|
ip = newIP
|
||||||
|
@ -72,12 +72,12 @@ func resolveIP(addr string, ipv6 bool) (string, error) {
|
|||||||
|
|
||||||
for i := 0; i < len(res); i++ {
|
for i := 0; i < len(res); i++ {
|
||||||
ip := res[i].String()
|
ip := res[i].String()
|
||||||
if strings.Contains(ip, ".") && !ipv6 {
|
if strings.IndexByte(ip, '.') != -1 && !ipv6 {
|
||||||
ipv4Resolved = true
|
ipv4Resolved = true
|
||||||
url[0] = ip
|
url[0] = ip
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if strings.Contains(ip, ":") && ipv6 {
|
if strings.IndexByte(ip, ':') != -1 && ipv6 {
|
||||||
ipv6Resolved = true
|
ipv6Resolved = true
|
||||||
url[0] = "[" + ip + "]"
|
url[0] = "[" + ip + "]"
|
||||||
break
|
break
|
||||||
|
Loading…
x
Reference in New Issue
Block a user