|
|
|
|
@ -68,7 +68,7 @@ func CheckSum(data []byte) (rt uint16) {
|
|
|
|
|
return ^rt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Ping(domain string, PS, Count int) {
|
|
|
|
|
func Ping(domain string, PS int) {
|
|
|
|
|
var (
|
|
|
|
|
icmp ICMP
|
|
|
|
|
laddr = net.IPAddr{IP: net.ParseIP("0.0.0.0")} // 得到本机的IP地址结构
|
|
|
|
|
@ -107,7 +107,8 @@ func Ping(domain string, PS, Count int) {
|
|
|
|
|
min_lan = 0.0
|
|
|
|
|
avg_lan = 0.0
|
|
|
|
|
|
|
|
|
|
for i := Count; i > 0; i-- {
|
|
|
|
|
icmp_seq := 1
|
|
|
|
|
for {
|
|
|
|
|
/*
|
|
|
|
|
向目标地址发送二进制报文包
|
|
|
|
|
如果发送失败就丢包 ++
|
|
|
|
|
@ -139,14 +140,16 @@ func Ping(domain string, PS, Count 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(), Count-i+1, 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)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("--- %s ping statistics ---\n", raddr.String())
|
|
|
|
|
|
|
|
|
|
fmt.Printf("%d packets transmitted, %f lost, %.2f%% packet loss, time 1000ms\n", Count, dropPack, dropPack/float64(Count)*100)
|
|
|
|
|
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
|
|
|
|
|
} else {
|
|
|
|
|
|