fix: number before failed

This commit is contained in:
2024-04-22 14:29:16 +08:00
parent 012d7c3246
commit 696ae9e758

10
main.go
View File

@@ -1,13 +1,14 @@
package main package main
import ( import (
flag "github.com/spf13/pflag"
"fmt" "fmt"
"net" "net"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"time" "time"
flag "github.com/spf13/pflag"
) )
func main() { func main() {
@@ -16,7 +17,7 @@ func main() {
count int count int
timeoutDuration time.Duration timeoutDuration time.Duration
infinite bool infinite bool
ipv6 bool ipv6 bool
successCount int successCount int
attemptCount int attemptCount int
@@ -78,7 +79,7 @@ func main() {
record = "AAAA" record = "AAAA"
} }
ip, err = filterIP(ips, ipv6) ip, err = filterIP(ips, ipv6)
if (err != nil) { if err != nil {
fmt.Printf("找不到 %s 的 %s 记录\n", hostname, record) fmt.Printf("找不到 %s 的 %s 记录\n", hostname, record)
os.Exit(1) os.Exit(1)
} }
@@ -101,11 +102,12 @@ func main() {
duration := time.Since(start) duration := time.Since(start)
attemptCount++ attemptCount++
fmt.Printf("[%d] ", i+1)
if err != nil { if err != nil {
fmt.Printf("测试到 %s 的连接失败: %s\n", address, "连接超时") fmt.Printf("测试到 %s 的连接失败: %s\n", address, "连接超时")
} else { } else {
successCount++ successCount++
fmt.Printf("[%d] 来自 %s 的响应: 时间=%s\n",i+1, address, fmt.Sprintf("%.3fms", float64(duration)/float64(time.Millisecond))) fmt.Printf("来自 %s 的响应: 时间=%s\n", address, fmt.Sprintf("%.3fms", float64(duration)/float64(time.Millisecond)))
conn.Close() conn.Close()
} }