How to make a complete NTP call using several servers?
Question: I need to independently check the current time (and, incidentally, cross check
with system provided time) and I wanted to use the NTP protocol for that.

There is an NTP module ([`ntplib`](https://pypi.python.org/pypi/ntplib/))
which allows to query **one** NTP server:

    
    
    >>> import ntplib
    >>> import time
    >>> time.ctime(ntplib.NTPClient().request('europe.pool.ntp.org', version=3).tx_time)
    'Wed Nov 18 17:17:16 2015'
    

I would like to use the NTP ability to combine the responses from several NTP
servers to get an [optimum
response](https://en.wikipedia.org/wiki/Network_Time_Protocol):

> [the NTP protocol] uses a modified version of Marzullo's algorithm to select
> accurate time servers and is designed to mitigate the effects of variable
> network latency.

What would be the right way in Python (ideally 3.x) to leverage that?


Answer: > What would be the right way in Python (ideally 3.x) to leverage that?

**Basically, you would have to implement Marzullo's algorithm in Python.**

Once you have queried two servers, how are you going to determine which clock
is closer to an atomic clock?

Determining the "optimum response"(a.k.a. most accurate time source) is tricky
business.

What you are looking for is an NTP `implementation`, unless you feel like
rolling your own in python.

The NTP Protocol discussed on the wiki page is talking about the NTP
[Reference
Implementation](https://en.wikipedia.org/wiki/Reference_implementation). This
consists of an ntp daemon running on all your servers. The ntp daemons keep
track of remote reference servers, and which ones are alive, and are most
accurate. Ntp daemon then slews or steps your clock to match the remote clock.

**Perhaps the easiest way** for you to achieve what you want, is to run an ntp
daemon(i.e. use the Reference Implementation) on your server in Client mode.
In your ntp.conf, list all of the time servers that you are trying to use to
find that "optimum response" from. When you have ntpd running, the daemon will
determine the lowest stratum, most accurate and available reference server for
you.

All you need to do is `ntpq -p`, and the remote server with the most accurate
time will be the server with the asterisk next to it.

Here's some sample output:

    
    
        remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
     LOCAL(0)        .LOCL.          10 l  96h   64    0    0.000    0.000   0.000
    *ns2.example.com 10.193.2.20      2 u  936 1024  377   31.234    3.353   3.096
    

