在 ip 报文的首部和 ICMP 报文的首部都可以放入时间戳数据。 clockdiff 程序正是使用时间戳来测算目的主机和本地主机的系统时间差。
语法格式:clockdiff [参数] [ip 地址]
常用参数:
-o | 使用 IP 时间戳选项来测量系统时间差。时间戳只用 3 个 |
-o1 | 使用 IP 时间戳选项来测量系统时间差。用 4 个时间戳。如果-o 和-o1 都没有设置,那么就是用 ICMP 时间戳来测试系统时间差 |
参考实例
[root@xtuos.com ~]# ping -T tsandaddr www.ustc.edu.cn -c 1 PING www.ustc.edu.cn (202.38.64.9) 56(124) bytes of data. 64 bytes from 202.38.64.9: icmp_seq=1 ttl=62 time=0.823 ms TS: lixi-desktop.local (210.45.74.25) 12522473 absolute 210.45.74.1 -251 local-gw.ustc.edu.cn (202.38.64.126) 248 202.38.64.9 -857514 Unrecorded hops: 3 --- www.ustc.edu.cn ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.823/0.823/0.823/0.000 ms
首先由上面的得出在 RRT 不大的时候,几个 ICMP 时间戳的关系。本地主机和 202.38.64.9 之间的时间差约为:-857514+248-251=-857517。分别用-o(IP 选项中时间戳)和不带选项(ICMP 路由时间戳)上述路由的系统时间进行测试。得到的结果:
[root@xtuos.com ~]# ./clockdiff -o 202.38.64.9 .................................................. host=202.38.64.9 rtt=1(0)ms/1ms delta=-857517ms/-857517ms Wed Dec 17 11:28:30 2008
[root@xtuos.com ~]# ./clockdiff 202.38.64.9 host=202.38.64.9 rtt=750(187)ms/0ms delta=-857517ms/-857517ms Wed Dec 17 11:28:35 2008
两种方法测试的都比较准确:
[root@xtuos.com ~]# ./clockdiff gigagate1.Princeton.EDU .................................................. host=gigagate1.Princeton.EDU rtt=307(21)ms/271ms delta=-5ms/-5ms Wed Dec 17 11:50:16 2008
上面是测试一个 RTT 较大的目的主机和本地主机的系统时间差。不过在使用 clockdiff 的时候,需要一点运气,因为很多路由会忽略 ICMP 或 IP 时间戳。