Skip to content

Latest commit

 

History

History
125 lines (69 loc) · 1.16 KB

ntp.md

File metadata and controls

125 lines (69 loc) · 1.16 KB
date author title url tags series categories toc draft
2022-04-08 11:41:02 +0800
Rustle Karl
NTP 网络时间协议
posts/protocols/docs/net/udp/ntp
Protocols
README
Protocols 学习笔记
学习笔记
true
false

协议原文参考

SNTP 简单网络时间协议

import socket
import struct
import time

TIME1997 = 2208988800
NTP_SERVER = "pool.ntp.org"

client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

data = b"\x1b" + 47 * b"\0"
client.sendto(data, (NTP_SERVER, 123))
data, address = client.recvfrom(1024)
print("response received from server:", address)

ts = struct.unpack("!12L", data)
t = ts[10]
t -= TIME1997
print(time.ctime(t))

协议原文参考

二级

三级

协议原文参考

二级

三级

协议原文参考

二级

三级

协议原文参考

二级

三级