From 0dac3c9fa21749d3e2a484d4a8b7a3457001d773 Mon Sep 17 00:00:00 2001 From: dustoair <107600816+dustoair@users.noreply.github.com> Date: Thu, 18 Aug 2022 09:58:52 +0800 Subject: [PATCH] read ip4 10.0.20.12->103.97.129.254: i/o timeout --- goping/goping.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/goping/goping.go b/goping/goping.go index d311f69..bacc54e 100644 --- a/goping/goping.go +++ b/goping/goping.go @@ -119,23 +119,32 @@ func Ping(domain string, PS int) { yellow := color.New(color.FgYellow).SprintFunc() for { /* - 向目标地址发送二进制报文包 - 如果发送失败就丢包 ++ + 向目标地址发送二进制报文包 + 如果发送失败就丢包 ++ + 这种判断其实不必要 发包一定可以 error返回一定是nil */ - index, err := conn.Write(buffer.Bytes()) - if err != nil { - //这种判断其实不必要 发包一定可以 error返回一定是nil - fmt.Printf("%s\n", red("timeout", index)) - dropPack++ - time.Sleep(time.Second) - continue - } + //index, err := conn.Write(buffer.Bytes()) + //if err != nil { + // //这种判断其实不必要 发包一定可以 error返回一定是nil + // fmt.Printf("%s\n", red("timeout", index)) + // dropPack++ + // time.Sleep(time.Second) + // continue + //} // 否则记录当前得时间 t_start := time.Now() conn.SetReadDeadline((time.Now().Add(time.Second * 3))) len, err := conn.Read(recv) - fmt.Println(len, err) + //strings.Contains(err.Error(), "timeout") + //超时状态 len=0 error包含 read ip4 10.0.20.12->103.97.129.254: i/o timeout + if len == 0 && err != nil { + fmt.Printf("%s\n", red("timeout")) + dropPack++ + time.Sleep(time.Second) + continue + } + /* 查目标地址是否返回失败 如果返回失败则丢包 ++