Skip to content

Instantly share code, notes, and snippets.

@BirkhoffLee
Forked from adulau/test-ntp.py
Created August 27, 2022 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BirkhoffLee/d1f8ae7c1a5374e3ac4e0917cd7eec9f to your computer and use it in GitHub Desktop.
Save BirkhoffLee/d1f8ae7c1a5374e3ac4e0917cd7eec9f to your computer and use it in GitHub Desktop.
test-ntp.py - Test a set of IP addresses for active NTP services
#!/usr/bin/env python
#
# Requirements: ntplib (easy_install ntplib)
#
# How to use it using GNU parallel (to run in //):
#
# cut -f1 -d";" ntp-monlist-servers.csv | parallel "python test-ntp.py --ip {1}"
#
# Software is free software released under the "Modified BSD license"
#
# Copyright (c) 2014 Alexandre Dulaunoy - alexandre.dulaunoy@circl.lu
import ntplib
from time import ctime
import argparse
parser = argparse.ArgumentParser( description="test-ntp.py - Test a set of IP addresses for NTP " )
parser.add_argument("--ip", action="append", help="IP address to check for NTP")
a = parser.parse_args()
if a.ip is not None:
c = ntplib.NTPClient()
for ip in a.ip:
try:
response = c.request(ip)
if response:
print (ip+" NTP Active "+ ctime(response.tx_time))
except:
print (ip+" NTP Deactivated")
else:
parser.print_help()
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment