-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_sync.py
48 lines (31 loc) · 932 Bytes
/
check_sync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#Program for system time clock sync
"""
Requires Internet Connection
Reference
https://pypi.org/project/ntplib/
"""
"""
Devansh Shukla
"""
import os
import ntplib # pip3 install ntplib
from datetime import datetime, timezone
def check_sync():
try:
#print("\n Connecting to NTP Server")
c = ntplib.NTPClient()
# Provide the respective ntp server ip in below function
response = c.request('time.nplindia.org', version=3)
#print(response.offset)
#print(ntplib.leap_to_text(response.leap))
server_time = datetime.fromtimestamp(response.tx_time)
current_time = datetime.now()
t1 = server_time.timestamp()
#print(t1)
t2 = current_time.timestamp()
#print(t2)
print("Difference in Sync is " , t2 - t1 , "s")
except:
print("Required Internet Connection")
exit(0)
check_sync()