|
|
|
|
@ -110,6 +110,8 @@ func Ping(domain string, PS int) {
|
|
|
|
|
avg_lan = 0.0
|
|
|
|
|
|
|
|
|
|
icmp_seq := 1
|
|
|
|
|
|
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
|
for {
|
|
|
|
|
/*
|
|
|
|
|
向目标地址发送二进制报文包
|
|
|
|
|
@ -142,21 +144,28 @@ func Ping(domain string, PS int) {
|
|
|
|
|
if dur > min_lan {
|
|
|
|
|
min_lan = dur
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=%.3f ms\n", len, raddr.String(), raddr.String(), icmp_seq, dur)
|
|
|
|
|
//fmt.Printf("来自 %s 的回复: 大小 = %d byte 时间 = %.3fms\n", raddr.String(), len, dur)
|
|
|
|
|
icmp_seq++
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
case s := <-c:
|
|
|
|
|
signal.Notify(c, os.Interrupt, os.Kill)
|
|
|
|
|
fmt.Println("Got signal:", s)
|
|
|
|
|
foot(raddr.String(), icmp_seq, dropPack,min_lan,avg_lan,max_lan,ret_list)
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
default:
|
|
|
|
|
fmt.Printf("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=%.3f ms\n", len, raddr.String(), raddr.String(), icmp_seq, dur)
|
|
|
|
|
//fmt.Printf("来自 %s 的回复: 大小 = %d byte 时间 = %.3fms\n", raddr.String(), len, dur)
|
|
|
|
|
icmp_seq++
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(c, os.Interrupt, os.Kill)
|
|
|
|
|
|
|
|
|
|
s := <-c
|
|
|
|
|
fmt.Println("Got signal:", s)
|
|
|
|
|
|
|
|
|
|
fmt.Printf("--- %s ping statistics ---\n", raddr.String())
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func foot(address string, icmp_seq int, dropPack, min_lan,avg_lan, max_lan float64,ret_list []float64{}) {
|
|
|
|
|
fmt.Printf("--- %s ping statistics ---\n", address)
|
|
|
|
|
fmt.Printf("%d packets transmitted, %f lost, %.2f%% packet loss, time 1000ms\n", icmp_seq, dropPack, dropPack/float64(icmp_seq)*100)
|
|
|
|
|
if len(ret_list) == 0 {
|
|
|
|
|
avg_lan = 3000.0
|
|
|
|
|
@ -169,8 +178,5 @@ func Ping(domain string, PS int) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("rtt min/avg/max/mdev = %.3f/%.3f/%.3f ms", min_lan, avg_lan, max_lan)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func foot() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|