Linux
顯示缺失的 icmp_seq 計數 |ping 命令
我正在尋找
ICMP
在執行 ping 命令時顯示失去的包或在輸出中顯示失敗的東西。下面的例子我們缺少 icmp_seq 計數的目前輸出。
64 bytes from 192.168.56.11: icmp_seq=38 ttl=64 time=1.23 ms 64 bytes from 192.168.56.11: icmp_seq=52 ttl=64 time=0.831 ms 64 bytes from 192.168.56.11: icmp_seq=53 ttl=64 time=0.679 ms 64 bytes from 192.168.56.11: icmp_seq=54 ttl=64 time=0.679 ms 64 bytes from 192.168.56.11: icmp_seq=55 ttl=64 time=0.679 ms 64 bytes from 192.168.56.11: icmp_seq=56 ttl=64 time=0.679 ms
所需的輸出將計算 icmp_seq 如果失去則顯示錯誤
64 bytes from 192.168.56.11: icmp_seq=51 ttl=64 time=1.23 ms 64 bytes from 192.168.56.11: icmp_seq=52 ttl=64 time=0.831 ms 64 bytes from 192.168.56.11: icmp_seq=53 ttl=64 time=0.679 ms Failed Failed Failed Failed 64 bytes from 192.168.56.11: icmp_seq=58 ttl=64 time=0.679 ms 64 bytes from 192.168.56.11: icmp_seq=59 ttl=64 time=0.679 ms Failed Failed Failed
檢查此程式碼
這只是解析 ping 輸出
bash-4.1$ cat ping.awk #!/usr/bin/awk -f # # analyzes ping output on Linux and looks for missed returns # based on icmp_seq # # ping output is expected on stdin # BEGIN { num = 0 } $5 ~ /icmp_seq=/ { split($5, res, /=/); if (res[2] != num + 1) { print "missed between", num, "and", res[2] } num = res[2]; } bash-4.1$ cat ping_result.txt 64 bytes from 192.168.56.11: icmp_seq=38 ttl=64 time=1.23 ms 64 bytes from 192.168.56.11: icmp_seq=52 ttl=64 time=0.831 ms 64 bytes from 192.168.56.11: icmp_seq=53 ttl=64 time=0.679 ms bash-4.1$ awk -f ping.awk ping_result.txt missed between 0 and 38 missed between 38 and 52
在Linux 上,可以使用:
fping -l google.com
上面的命令將顯示統計資訊:
- 每個請求的平均經過時間。
- 整體失去包裹的百分比。
樣本輸出
google.com : [160], 84 bytes, 32.0 ms (39.1 avg, 0% loss) google.com : [161], 84 bytes, 32.3 ms (39.1 avg, 0% loss) google.com : [162], 84 bytes, 33.8 ms (39.1 avg, 0% loss) google.com : [163], 84 bytes, 31.3 ms (39.0 avg, 0% loss) google.com : [164], 84 bytes, 32.8 ms (39.0 avg, 0% loss) google.com : [165], 84 bytes, 37.3 ms (39.0 avg, 0% loss) google.com : [166], 84 bytes, 32.4 ms (38.9 avg, 0% loss) google.com : [167], 84 bytes, 36.1 ms (38.9 avg, 0% loss) google.com : [168], 84 bytes, 32.8 ms (38.9 avg, 0% loss) google.com : [169], 84 bytes, 33.8 ms (38.8 avg, 0% loss) google.com : [170], 84 bytes, 32.6 ms (38.8 avg, 0% loss) google.com : [171], 84 bytes, 33.0 ms (38.8 avg, 0% loss) google.com : [172], 84 bytes, 33.2 ms (38.7 avg, 0% loss) ^C google.com : xmt/rcv/%loss = 173/173/0%, min/avg/max = 31.3/38.7/261
尖端:
ctrl + c
停止它,它會顯示額外的統計數據行,包括:發送的包裹/接收的包裹/失去的百分比,最小/平均/最大經過時間。
安裝
預設不安裝,可以通過以下方式安裝:
- Ubuntu / 薄荷
sudo apt install fping