import socket
import struct
import time
ntp = 'pool.ntp.org'
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
data = '\x1b' + 47 * '\x00'
client.sendto(data, (ntp, 123))
data, address = client.recvfrom(1024)
if data:
    print('Response received from:', address)
t = struct.unpack('!12I', data)[10]
t -= 2208988800
print('\tTime=%s' % time.ctime(t))
Measuring elapsed time in python