Prototype Python version of ntpdig lands.
Eric S. Raymond
esr at thyrsus.com
Mon Nov 7 13:09:26 UTC 2016
Well, *that* didn't take a lot of work. After reading a couple of articles
on the Web about simple SNTP clients in Python, I decided to take a swing
at the ntpdig replacement. Two days later it's mostly there; look in
The querying stuff works perfectly; you can't readily tell the old-style
or JSON output from that of the C version. A few things are still missing;
the big two are authentication support and actual time-stepping/slewing.
The logging needs to be changed to use syslog, and there's one reply
validation it should be doing that it doesn't yet. None of these
things will be difficult or take a lot of code.
I've added one new feature. Rather than simply taking the first sample
it can get, pyntpdig has the ability to take multiple samples, apply
bogon filtering, and choose the best. This is behavior similar to
Classic's ntpdate - in fact I swiped the filtering code from ntpdate
(then simplified it somewhat).
Even with the new feature, the Python code is smaller than the C ntpdig
code by a factor of 9.6, and not likely to get much larger. That's an
unusually high degree of compression - I generally see ratios of 2:1
to 5:1. And it's a big gain in maintainability down the road.
In the process of working on this I learned that the C ntpdig code is
a pretty extreme example of "because I can" overengineering. Asynchronous
DNS lookup, when the typical query is one host, usually a pool server?
Please test this code and eyeball-review it. I expect to finish it over
the next week.
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
More information about the devel