Created
October 27, 2016 01:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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