Skip to content

Instantly share code, notes, and snippets.

@adulau
Created January 24, 2014 13:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adulau/8597533 to your computer and use it in GitHub Desktop.
Save adulau/8597533 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)
@msterhuj
Copy link

thx 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment