新增 支持 IPv4 与 IPv6 混合测速; 移除 -ipv6 参数(已无用)

This commit is contained in:
xiu2
2022-11-08 15:47:19 +08:00
parent ce22f6b2a4
commit 021914f975
6 changed files with 32 additions and 34 deletions

View File

@@ -62,11 +62,7 @@ func (p *Ping) Run() utils.PingDelaySet {
if len(p.ips) == 0 {
return p.csv
}
ipVersion := "IPv4"
if IPv6 { // IPv6 模式判断
ipVersion = "IPv6"
}
fmt.Printf("开始延迟测速模式TCP %s端口%d平均延迟上限%v ms平均延迟下限%v ms)\n", ipVersion, TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
fmt.Printf("开始延迟测速模式TCP端口%d平均延迟上限%v ms平均延迟下限%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
for _, ip := range p.ips {
p.wg.Add(1)
p.control <- false
@@ -87,9 +83,10 @@ func (p *Ping) start(ip *net.IPAddr) {
//bool connectionSucceed float32 time
func (p *Ping) tcping(ip *net.IPAddr) (bool, time.Duration) {
startTime := time.Now()
fullAddress := fmt.Sprintf("%s:%d", ip.String(), TCPPort)
//fmt.Println(ip.String())
if IPv6 { // IPv6 需要加上 []
var fullAddress string
if isIPv4(ip.String()) {
fullAddress = fmt.Sprintf("%s:%d", ip.String(), TCPPort)
} else {
fullAddress = fmt.Sprintf("[%s]:%d", ip.String(), TCPPort)
}
conn, err := net.DialTimeout("tcp", fullAddress, tcpConnectTimeout)