A simple NTP client (written in Python) to determine the LI state of a
remote peer.
1:45pm [EMAIL PROTECTED] [~/projects/ntp] ./ntp_li_test.py -h
time.nrc.ca
The leap indicator bit is set and is positive.
1:45pm [EMAIL PROTECTED] [~/projects/ntp] ./ntp_li_test.py -h
time.nist.gov
The leap indicator is not set.
1:46pm [EMAIL PROTECTED] [~/projects/ntp] ./ntp_li_test.py -h
navobs1.usnogps.navy.mil
The leap indicator is not set.
Enjoy.
#!/usr/local/bin/python
#
# Written amidst my christmas ennui.
# email: [EMAIL PROTECTED]
#
import sys
import getopt
import socket
try:
options, arguments = getopt.getopt( sys.argv[ 1: ], "h:" )
if( len( options ) == 0 ):
print sys.argv[ 0 ] + " : Please use the -h argument to specify a host
to examine."
sys.exit( -1 )
for option, argument in options:
if( option == "-h" ):
if( len( argument ) == 0 ):
print "You must specify a host."
sys.exit( -1 )
peer = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
peer.connect( ( argument, 123 ) )
request = chr( 0x23 )
request += "\x00"* 47
peer.sendall( request )
response = peer.recv( 48 )
leap = ord( response[ 0 ] ) >> 6
if( leap & 0x1 ):
print "The leap indicator bit is set and is positive."
elif( leap & 0x2 ):
print "The leap indicator bit is set and is negative."
elif( leap & 0x3 ):
print "The leap indicator is set in an alarm condition."
else:
print "The leap indicator is not set."
except getopt.error, msg:
print msg
sys.exit( -1 )
_______________________________________________
timekeepers mailing list
[email protected]
https://fortytwo.ch/mailman/cgi-bin/listinfo/timekeepers