Created
January 24, 2014 13:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 - [email protected] | |
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
thx 👍