[Git][NTPsec/ntpsec][master] Code reuse - teach ntptrace to use ntp.util.

Eric S. Raymond gitlab at mg.gitlab.com
Fri Sep 9 12:16:30 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
7226de82 by Eric S. Raymond at 2016-09-09T08:15:44-04:00
Code reuse - teach ntptrace to use ntp.util.

- - - - -


3 changed files:

- docs/includes/ntptrace-body.txt
- + ntptrace/ntp
- ntptrace/ntptrace


Changes:

=====================================
docs/includes/ntptrace-body.txt
=====================================
--- a/docs/includes/ntptrace-body.txt
+++ b/docs/includes/ntptrace-body.txt
@@ -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:


=====================================
ntptrace/ntp
=====================================
--- /dev/null
+++ b/ntptrace/ntp
@@ -0,0 +1 @@
+../pylib
\ No newline at end of file


=====================================
ntptrace/ntptrace
=====================================
--- a/ntptrace/ntptrace
+++ b/ntptrace/ntptrace
@@ -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='')



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/7226de829d1310149a3bbfc7fbeaddb0380dfc3b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160909/22823fc0/attachment.html>


More information about the vc mailing list