Skip to content

Instantly share code, notes, and snippets.

@ochinchina
Created October 27, 2016 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochinchina/aeacd02b6021b2b59da17d496583b8aa to your computer and use it in GitHub Desktop.
Save ochinchina/aeacd02b6021b2b59da17d496583b8aa to your computer and use it in GitHub Desktop.
get the date time from the web site by http head and set it as the system time
#!/usr/bin/python2
import subprocess
import re
import os
import time
def set_os_date( url ):
header = subprocess.check_output( ["curl", "--head", url ], shell=False )
for line in header.split("\n"):
if re.match(r'^Date:', line ):
try:
os.system( 'date -R --set="%s"' % line[6:] )
return True
except:
pass
return False
web_sites = ["http://google.com", "http://baidu.com", "https://github.com"]
while True:
for url in web_sites:
if set_os_date(url):
break
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment