Python/Python Programming
[ Python ] ntplib 모듈을 이용한 시간 동기화 점검
Pydole
2023. 5. 14. 13:22
ntplib 모듈설치
pip install ntplib
NTP서버와 로컬간의 offset 체크
import ntplib
from time import ctime
timeServer = 'time.windows.com' # NTP Server Domain Or IP
c = ntplib.NTPClient()
response = c.request(timeServer, version=3)
print('NTP Server Time과 Local Time과 차이는 %.2f s입니다.' %response.offset)
--------------------------------------------------------------------
NTP Server Time과 Local Time과 차이는 0.71 s입니다.
NTP 서버시간 타임 스탬프로 출력
import ntplib
from time import ctime
timeServer = 'time.windows.com' # NTP Server Domain Or IP
c = ntplib.NTPClient()
response = c.request(timeServer, version=3)
print(ctime(response.tx_time))
---------------------------------------------------------------------
Mon May 21 11:20:51 2018