Googleホスト更新脚本

  

# - * - coding:utf-8 - * -__ author__ = 'xu.zhibin' __ createDateTime__ = '2012-06-25 11:54'インポートosimport sysimport再インポートurllib2updateUrl =" https://smarthosts.googlecode.com/svn/trunk/hosts"hostPath="C:\\WINDOWS\\system32\\drivers\\etc\\hosts"pattern=re.compile(r"#GoogleサービスSTART([\\ s | \\ S] *)#Googleサービス終了")#最新のGoogle Hoststry:updateHost = urllib2.urlopen(updateUrl)updateContent = updateHost.read()を除く例外、例:print"最新のGoogle Hostsが失敗した! raw_input()sys.exit()match = pattern.search(updateContent)、match!= Noneの場合:googleContent = updateContent [match.start():match.end()]#本地HostshostFile = open(hostPath、 'r +') hostContent = hostFile.read()bakContent = pattern( ''、hostContent)bakContent = re( "\\ n \\ n"、 "\\ n"、bakContent)hostContent = googleContent + "\\ n" + bakContenthostFile.seek(0)hostFile.write(hostContent)hostFile.close()#ホストファイルbakPath ="%s_bak" %hostPathbakFile = open(bakPath、 'w')bakFile.write(bakContent)bakFile.close()print"ホストの更新に成功しました。" raw_input()
en"],null,[0.98865479],en"]]]

Copyright © Windowsの知識 All Rights Reserved