From eada32826b0aa8060b8c62dfc310473ec55efddd Mon Sep 17 00:00:00 2001 From: dustoair <107600816+dustoair@users.noreply.github.com> Date: Thu, 18 Aug 2022 10:10:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E5=A4=A7=E4=B8=A2=E5=8C=85=E6=95=B0?= =?UTF-8?q?=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- goping/goping.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/goping/goping.go b/goping/goping.go index 4d01db5..38990af 100644 --- a/goping/goping.go +++ b/goping/goping.go @@ -105,6 +105,7 @@ func Ping(domain string, PS int) { recv := make([]byte, 1024) ret_list := []float64{} + maxLost := 3 // 最大丢包数 dropPack := 0.0 /*统计丢包的次数,用于计算丢包率*/ max_lan = 3000.0 min_lan = 0.0 @@ -153,6 +154,9 @@ func Ping(domain string, PS int) { if err != nil { fmt.Printf("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=1000 %s\n", len, raddr.String(), raddr.String(), icmp_seq, red("ms")) dropPack++ + if int(dropPack) >= maxLost { + os.Exit(0) + } time.Sleep(time.Second) continue }