Python code for modifying operating system time

From , 3 Years ago, written in Python, viewed 224 times.
URL https://pastebin.vip/view/90610aa0
  1. #-*- coding:utf-8 -*-
  2.  
  3. import socket
  4. import struct
  5. import time
  6. import win32api
  7.  
  8. TimeServer = '210.72.145.44' #国家授时中心ip
  9. Port = 123
  10.  
  11. def getTime():
  12.     TIME_1970 = 2208988800L
  13.     client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  14.     data = '\x1b' + 47 * '\0'
  15.     client.sendto(data, (TimeServer, Port))
  16.     data, address = client.recvfrom(1024)
  17.     data_result = struct.unpack('!12I', data)[10]
  18.     data_result -= TIME_1970
  19.     return data_result
  20.  
  21. def setSystemTime():
  22.     tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst = time.gmtime(getTime())
  23.     win32api.SetSystemTime(tm_year, tm_mon, tm_wday, tm_mday, tm_hour, tm_min, tm_sec, 0)
  24.     print "Set System OK!"
  25.  
  26. if __name__ == '__main__':
  27.     setSystemTime()
  28.     print "%d-%d-%d %d:%d:%d" % time.localtime(getTime())[:6]
  29. #//python/6453

Reply to "Python code for modifying operating system time"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website