0

if the user edits the computer system date time, how can it be checked against the date and time zone with code python. Thanks all!

1 Answers1

0

Python use the system datetime.

 import datetime
 x = datetime.datetime.now()
 print(x)

Run this and then run it after you turn you system clock back one hour.

This will print an NTP server time followed by the system time. Can be modified to compare the two.

import socket
import struct
import sys
import time
import datetime

def RequestTimefromNtp(addr='0.de.pool.ntp.org'):
    REF_TIME_1970 = 2208988800  # Reference time
    client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    data = b'\x1b' + 47 * b'\0'
    client.sendto(data, (addr, 123))
    data, address = client.recvfrom(1024)
    if data:
        t = struct.unpack('!12I', data)[10]
        t -= REF_TIME_1970
        return time.ctime(t), t

if __name__ == "__main__":
    print(RequestTimefromNtp())
    x = datetime.datetime.now()
    print(x) 
stefan_aus_hannover
  • 1,777
  • 12
  • 13