接下來是實驗的環節了,在server端先啟動ping server
#> python ping.py
在client端發送ping
># ping 172.17.0.6
PING 172.17.0.6 (172.17.0.6) 56(84) bytes of data.
64 bytes from 172.17.0.6: icmp_seq=1 ttl=64 time=0.340 ms
64 bytes from 172.17.0.6: icmp_seq=1 ttl=64 time=1.72 ms (DUP!)
64 bytes from 172.17.0.6: icmp_seq=2 ttl=64 time=0.318 ms
64 bytes from 172.17.0.6: icmp_seq=2 ttl=64 time=0.695 ms (DUP!)
64 bytes from 172.17.0.6: icmp_seq=3 ttl=64 time=0.709 ms
64 bytes from 172.17.0.6: icmp_seq=3 ttl=64 time=0.994 ms (DUP!)
這裡就會看到有個duplicate的ping,代表一個是從系統發送的reply,一個是我們server發送的
那我們想關掉server的ping reply server呢?,在server端跑這個指令
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
代表我們忽略所有ping reply
如果想在對ping注入延遲,在sock.send之前讓他睡個10毫秒
time.sleep(0.01)
可以看到如下結果
># ping 172.17.0.6
PING 172.17.0.6 (172.17.0.6) 56(84) bytes of data.
64 bytes from 172.17.0.6: icmp_seq=1 ttl=64 time=10.146 ms
64 bytes from 172.17.0.6: icmp_seq=2 ttl=64 time=10.395 ms
64 bytes from 172.17.0.6: icmp_seq=3 ttl=64 time=10.923 ms