Commit 7226de82 authored by Eric S. Raymond's avatar Eric S. Raymond
Browse files

Code reuse - teach ntptrace to use ntp.util.

parent 1a7fed9b
......@@ -12,11 +12,16 @@
== DESCRIPTION ==
+ntptrace+ is a python script that uses the {ntpq} utility program to follow
the chain of NTP servers from a given host back to the primary time
source. For ntptrace to work properly, each of these servers must
+ntptrace+ is a python script that uses the {ntpq} utility program to
follow the chain of NTP servers from a given host back to the primary
time source.
For +ntptrace+ to work properly, each of these servers must
implement the NTP Control and Monitoring Protocol specified in RFC 1305
and enable NTP Mode 6 packets.
and enable NTP Mode 6 control packets. Nowadays it is usual for
public timeservers to disable Mode 6 queries, so this script is
unlikely to be very useful unless you have a collectioon of
specially-configured timeservers on your LAN.
If given no arguments, ntptrace starts with localhost. Here is an
example of the output from ntptrace:
......
../pylib
\ No newline at end of file
......@@ -17,7 +17,7 @@ import re
import socket
import subprocess
import sys
import ntp.util
def get_info(host):
info = ntp_read_vars(0, [], host)
......@@ -84,21 +84,6 @@ def ntp_read_vars(peer, vars, host):
return outvars
def do_dns(hostname):
try:
ai = socket.getaddrinfo(hostname, None, 0, 0, 0,
socket.AI_CANONNAME)
except socket.gaierror as e:
print('getaddrinfo failed: %s' % e.strerr, file=sys.stderr)
raise SystemExit(1)
(family, socktype, proto, canonname, sockaddr) = ai[0]
try:
name = socket.getnameinfo(sockaddr, socket.NI_NAMEREQD)
except socket.gaierror:
return canonname.lower()
return name[0].lower()
usage = r"""ntptrace - Trace peers of an NTP server.
USAGE: ntptrace [ -<flag> [<val>] | --<name>[{=| }<val>] ]... [host]
......@@ -148,7 +133,7 @@ while True:
break
if not numeric:
host = do_dns(host)
host = ntp.util.canonicalize_dns(host)
print("%s: stratum %d, offset %f, synch distance %f" %
(host, int(info['stratum']), info['offset'], info['syncdistance']), end='')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment