本文的代码来源于《Python Network Programming Cookbook》中的1_12示例代码,书中代码是2.7版本的,我修改后在3.8环境下测试ok。
#!/usr/bin/env python
# Python Network Programming Cookbook -- Chapter -1
# This program is optimized for Python 3.8 It may run on any
# other Python version with/without modifications.
# 编写一个sntp客户端
import socket
import struct
import time
NTP_SERVER = "0.uk.pool.ntp.org"
TIME1970 = 2208988800
def sntp_client