|
|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
查目标地址是否返回失败
|
|
|
|
|
如果返回失败则丢包 ++
|
|
|
|
|
|