Book Image

Learning Python Network Programming

By : Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington
Book Image

Learning Python Network Programming

By: Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington

Overview of this book

Table of Contents (17 chapters)
Learning Python Network Programming
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

NTP clients


The final topic that will be covered in this chapter is NTP. Synchronizing time with a centralized time server is a key step in any corporate network. We would like to compare the log files between various servers and see if the timestamp on each server is accurate; the log events may not then co-relate. Many authentication protocols, such as Kerberos, strictly rely on the accuracy of the time stamp reported by the client to the servers. Here, a third-party Python ntplib library will be introduced, and then the communication between the NTP client and the server will be investigated.

To create an NTP client, you need to call the ntplib's NTPCLient class.

import ntplib
from time import ctime
c = ntplib.NTPClient()
response = c.request('pool.ntp.org')
print ctime(response.tx_time)

Here, we have selected pool.ntp.org, which is a load-balanced webserver. So, a pool of the NTP servers will be ready to respond to the client's request. Let's find more information regarding this from...