您可以查看 RFC1323,并使用 TSval 和 TSecr 计算 RTT。为避免复杂性,您可以在连接建立后尝试在三次握手时使用 SYN-SYN/ACK-ACK。像这样的东西...
12:02:22.549838 IP xxx.xxx.xxx.xxx.34400 > yyy.yyy.yyy.yyy.80: Flags [S], seq 3721025326, win 26883, options [mss 8961,sackOK,TS val 2130701590 ecr 0,nop,wscale 7], length 0
12:02:22.827325 IP yyy.yyy.yyy.yyy.80 > xxx.xxx.xxx.xxx.34400: Flags [S.], seq 506523745, ack 3721025327, win 42408, options [mss 1380,sackOK,TS val 41895331 ecr 2130701590,nop,wscale 8], length 0
12:02:22.827383 IP xxx.xxx.xxx.xxx.34400 > yyy.yyy.yyy.yyy.80: Flags [.], ack 1, win 211, options [nop,nop,TS val 2130701660 ecr 41895331], length 0
SYN => TS val 2130701590
SYN/ACK => ecr 2130701590,TS val 41895331
ACK => TS 验证码 2130701660
RTT = 2130701660 - 2130701590 = 70(我认为单位是毫秒)
>>> capture = sniff(filter="port 80", timeout = 10, count = 50)
>>> tsvaltmp = 0
>>> tsecrtmp = 0
>>> for pkt in capture:
... tsdata=dict(pkt['TCP'].options)
... tsvalpkt = tsdata['Timestamp'][0]
... tsecrpkt = tsdata['Timestamp'][1]
... if tsvaltmp == tsecrpkt:
... rtt = tsvalpkt - tsecrtmp
... if rtt != 0 and tsecrtmp != 0:
... print rtt
... tsvaltmp = tsvalpkt
... tsecrtmp = tsecrpkt
...
6014
8
8
8
6310
9
>>>