小编Mat*_*att的帖子

Python ntplib 响应中的所有字段是什么,它们是如何使用的?

我想测量本地时钟和运行 NTP 服务器的远程处理器之间的差异。

我可以获得响应的 tx_time,如下所示,但更好的估计将包括对网络延迟的一些估计。NTP 响应消息中还有其他字段也应该使用。

import ntplib
from time import ctime,time

addr_remote = '128.128.204.207'

c = ntplib.NTPClient()
remote = c.request(addr_remote)
local = time()
print("REMOTE: " + ctime(remote.tx_time) + "   <reference clock>   ") 
print("LOCAL:  " + ctime(local)        + "   delta: " + str(local - remote.tx_time ))
Run Code Online (Sandbox Code Playgroud)

如果我看“远程”:

for attr in dir(remote):
    print("remote.%s = %r" % (attr, getattr(remote, attr)))
Run Code Online (Sandbox Code Playgroud)

我懂了:

remote.delay = 0.0
remote.dest_time = 1531863145.9309998
remote.dest_timestamp = 3740851945.9309998
remote.from_data = <bound method NTPPacket.from_data of <ntplib.NTPStats object at 0x000000000265B2E8>>
remote.leap = …
Run Code Online (Sandbox Code Playgroud)

python ntp

6
推荐指数
1
解决办法
2516
查看次数

标签 统计

ntp ×1

python ×1