[Git][NTPsec/ntpsec][master] add s, S, srcname, srcnumber options to use srchost & dug names or numbers

Eric S. Raymond gitlab at mg.gitlab.com
Wed Sep 2 12:40:00 UTC 2020



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


Commits:
000dfdce by James Browning at 2020-09-02T12:31:13+00:00
add s, S, srcname, srcnumber options to use srchost & dug names or numbers

- - - - -


5 changed files:

- docs/includes/ntpmon-body.adoc
- docs/includes/ntpq-body.adoc
- ntpclients/ntpmon.py
- ntpclients/ntpq.py
- pylib/util.py


Changes:

=====================================
docs/includes/ntpmon-body.adoc
=====================================
@@ -60,7 +60,8 @@ k:: Select previous peer (in select mode); arrow up also works.
 
 m:: Toggle MRUlist-only mode; suppresses peer display when on.
 
-n:: Toggle display of hostnames vs. IP addresses (default is hostnames).
+n:: Toggle display of hostnames vs. IP addresses vs ntpd supplied names plus
+    IP addresses or ntpd supplied names and hostnames (default is hostnames).
 
 o:: Change peer display to opeers mode, showing destination address.
 
@@ -98,6 +99,10 @@ x:: Cleanly terminate the program.
 
 -n:: Show IP addresses (vs. hostnames)
 
+-s, --srcname:: Show srchost first then names and numbers
+
+-S, --srcnumber:: Show srchost first then numbers
+
 -u:: Show units
 
 -V:: Display version and exit.


=====================================
docs/includes/ntpq-body.adoc
=====================================
@@ -79,6 +79,12 @@ read interactive format commands from the standard input.
   converting to the canonical host names.  You may get hostnames
   anyway for peers in the initialization phase before DNS has resolved
   the peer name.
++-s+, +--srcname+::
+  Output host adresses by: Names passed to ntpd, then names reverse
+  resolved from addresses and finally, ip addresses themselves 
++-S+, +--srcnumber+::
+  Output host adresses by: Names passed to ntpd, then ip addresses
+  themselves 
 +-p+, +--peers+::
   Print a list of the peers known to the server as well as a summary of
   their state; this is equivalent to the +peers+ interactive command.


=====================================
ntpclients/ntpmon.py
=====================================
@@ -218,17 +218,18 @@ if __name__ == '__main__':
         sys.stderr.write("Module: %s\n" % ntp.util.stdversion())
     try:
         (options, arguments) = getopt.getopt(sys.argv[1:],
-                                             "dD:hl:nuV",
+                                             "dD:hl:nsSuV",
                                              ["debug", "help", "logfile=",
                                               "numeric", "units",
-                                              "set-debug-level=", "version"])
+                                              "set-debug-level=", "version",
+                                              "srcname", "srcnumber"])
     except getopt.GetoptError as e:
         sys.stderr.write("%s\n" % e)
         sys.stderr.write(usage)
         raise SystemExit(1)
     progname = sys.argv[0]
 
-    showhostnames = True
+    showhostnames = 1
     wideremote = False
     showall = True
     showpeers = True
@@ -252,7 +253,11 @@ if __name__ == '__main__':
                 logfp.close()
             logfp = open(val, "a", 1)  # 1 => line buffered
         elif switch in ("-n", "--numeric"):
-            showhostnames = False
+            showhostnames = 0
+        elif switch in ("-s", "--srcname"):
+            showhostnames = 3
+        elif switch in ("-S", "--srcnumber"):
+            showhostnames = 2
         elif switch in ("-u", "--units"):
             showunits = True
         elif switch in ("-V", "--version"):
@@ -419,9 +424,16 @@ if __name__ == '__main__':
                         showpeers = not showpeers
                         detailmode = False  # detail + hide peers == crash
                     elif key == 'n':
-                        peer_report.showhostnames = \
-                            not peer_report.showhostnames
-                        mru_report.showhostnames = not mru_report.showhostnames
+                        if peer_report.showhostnames == 2:
+                            peer_report.showhostnames = 0
+                        elif peer_report.showhostnames == 0:
+                            peer_report.showhostnames = 1
+                        elif peer_report.showhostnames == 1:
+                            peer_report.showhostnames = 3
+                        else:
+                            peer_report.showhostnames = 2
+                        mru_report.showhostnames = \
+                            peer_report.showhostnames
                     elif key == 'o':
                         peer_report.displaymode = 'opeers'
                     elif key == 'p':


=====================================
ntpclients/ntpq.py
=====================================
@@ -71,7 +71,7 @@ class Ntpq(cmd.Cmd):
         #  so I am leaving them, and possibly duplicating them.
         self.rawmode = False            # Flag which indicates raw mode output.
         self.directmode = False         # Flag for direct MRU output.
-        self.showhostnames = True       # If false, display numeric IPs
+        self.showhostnames = 1          # If & 1 false, display numeric IPs
         self.showunits = False          # If False, show old style float
         self.auth_delay = 20            # delay time (default 20msec)
         self.wideremote = False         # show wide remote names?
@@ -442,7 +442,7 @@ usage: timeout [ msec ]
                 value = queried[name][0]
                 rawvalue = queried[name][1]
                 if fmt in (NTP_ADD, NTP_ADP):
-                    if self.showhostnames:
+                    if self.showhostnames[0]:
                         if self.debug:
                             self.say("DNS lookup begins...")
                         value = ntp.util.canonicalize_dns(
@@ -563,20 +563,29 @@ usage: passwd []
         if not line:
             pass
         elif line == "yes":
-            self.showhostnames = True
+            self.showhostnames = 1
         elif line == "no":
-            self.showhostnames = False
+            self.showhostnames = 0
+        elif line == 'hostnum':
+            self.showhostnames = 2
+        elif line == 'hostname':
+            self.showhostnames = 3
         else:
             self.say("What?\n")
-        if self.showhostnames:
-            self.say("hostnames being shown\n")
+            pass
+        if self.showhostnames & 1:
+            self.say('resolved hostnames being shown\n')
+        else:
+            self.say('resolved hostnames not being shown\n')
+        if self.showhostnames & 2:
+            self.say('supplied hostnames being shown\n')
         else:
-            self.say("hostnames not being shown\n")
+            self.say('supplied hostnames not being shown\n')
 
     def help_hostnames(self):
         self.say("""\
 function: specify whether hostnames or net numbers are printed
-usage: hostnames [yes|no]
+usage: hostnames [yes|no|hostname|hostnum]
 """)
 
     def do_debug(self, line):
@@ -1610,12 +1619,12 @@ if __name__ == '__main__':
     try:
         (options, arguments) = getopt.getopt(
             sys.argv[1:],
-            "46a:c:dD:hk:npVwW:ul:",
+            "46a:c:dD:hk:npsSVwW:ul:",
             ["ipv4", "ipv6", "authentication=",
              "command=", "debug", "set-debug-level=",
              "help", "keyfile", "numeric", "peers",
              "version", "wide", "width=", "units",
-             "logfile="])
+             "logfile=", "srcname", "srcnumber"])
     except getopt.GetoptError as e:
         sys.stderr.write("%s\n" % e)
         sys.stderr.write(usage)
@@ -1650,11 +1659,15 @@ if __name__ == '__main__':
             sys.stderr.write(usage)
             raise SystemExit(0)
         elif switch in ("-n", "--numeric"):
-            interpreter.showhostnames = False
+            interpreter.showhostnames = 0
         elif switch in ("-p", "--peers"):
             interpreter.ccmds.append("peers")
         elif switch in ("-k", "--keyfile"):
             keyfile = val
+        elif switch in ("-s", "--srcname"):
+            interpreter.showhostnames = 3
+        elif switch in ("-S", "--srcnumber"):
+            interpreter.showhostnames = 2
         elif switch in ("-V", "--version"):
             sys.stdout.write("ntpq %s\n" % version)
             raise SystemExit(0)


=====================================
pylib/util.py
=====================================
@@ -1139,7 +1139,9 @@ class PeerSummary:
                 and srcadr != "0.0.0.0" \
                 and not srcadr.startswith("127.127") \
                 and srcadr != "::":
-            if self.showhostnames:
+            if self.showhostnames & 2 and 'srchost' in locals() and srchost:
+                clock_name = srchost
+            elif self.showhostnames & 1:
                 try:
                     if self.debug:
                         self.logfp.write("DNS lookup begins...\n")
@@ -1231,7 +1233,7 @@ class MRUSummary:
         self.debug = debug
         self.logfp = logfp
         self.now = None
-        self.showhostnames = showhostnames      # If false, display numeric IPs
+        self.showhostnames = showhostnames  # If not [0], display numeric IPs
         self.wideremote = wideremote
 
     header = " lstint avgint rstr r m v  count    score   drop rport remote address"
@@ -1267,7 +1269,7 @@ class MRUSummary:
             rscode = '.'
         (ip, port) = portsplit(entry.addr)
         try:
-            if not self.showhostnames:
+            if not self.showhostnames & 1:
                 dns = ip
             else:
                 dns = canonicalize_dns(ip)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/000dfdcef9b2ae4a8ebf409123c8bc6979e723d6

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/000dfdcef9b2ae4a8ebf409123c8bc6979e723d6
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20200902/9667337d/attachment-0001.htm>


More information about the vc mailing list