I'd like to make a measurement of the difference between a local clock, and a remote processor running an NTP server.
I can get the tx_time of the response, as shown below, but a better estimate would include some estimate of the network delays. There are other fields in the NTP response message which should be used, as well.
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 ))
If I look at "remote":
for attr in dir(remote):
print("remote.%s = %r" % (attr, getattr(remote, attr)))
I see:
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 = 0
remote.mode = 4
remote.offset = -1.8789582252502441
remote.orig_time = 1531863145.9309998
remote.orig_timestamp = 3740851945.9309998
remote.poll = 0
remote.precision = -7
remote.recv_time = 1531863144.0520415
remote.recv_timestamp = 3740851944.0520415
remote.ref_id = 0
remote.ref_time = 0.0
remote.ref_timestamp = 2208988800.0
remote.root_delay = 0.0
remote.root_dispersion = 0.0
remote.stratum = 9
remote.to_data = <bound method NTPPacket.to_data of <ntplib.NTPStats object at 0x000000000265B2E8>>
remote.tx_time = 1531863144.0520415
remote.tx_timestamp = 3740851944.0520415
So, how do I use these:
- dest_time
- orig_time
- recv_time
- tx_time
to remove the network delays, and get a better estimate of the clock difference?