Google Hosts 脚本 脚本

  

# - * - codificación: utf-8 - * -__ author__ = 'xu.zhibin' __ createDateTime__ = '2012-06-25 11: 54'import osimport sysimport reimport urllib2updateUrl = " /smarthosts.googlecode.com/svn/trunk/hosts"hostPath="C:\\WINDOWS\\system32\\drivers\\etc\\hosts"pattern=re.compile(r"#Google Services START ([\\ s | \\ S] *) # Google Services END ") # 获取 最新 的 Google Hoststry: updateHost = urllib2.urlopen (updateUrl) updateContent = updateHost.read () excepto Exception, ej: print " 最新 的 Hos 的 quot " raw_input () sys.exit () match = pattern.search (updateContent) if match! = None: googleContent = updateContent [match.start (): match.end ()] # 本地 HostshostFile = open (hostPath, 'r +') hostContent = hostFile.read () bakContent = pattern.sub ('', hostContent) bakContent = re.sub (" \\ n \\ n ", " \\ n ", bakContent) hostContent = googleContent + " \\ n " + bakContenthostFile.seek (0) hostFile.write (hostContent) hostFile.close () # Hosts 备份 bakPath = "% s_bak " % hostPathbakFile = open (bakPath, 'w') bakFile.write (bakContent) bakFile.close () print " 更新 Hosts 成功! " raw_input ()
en"],null,[0.98865479],en"]]]

Copyright © Conocimiento de Windows All Rights Reserved