-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle3.py
More file actions
31 lines (29 loc) · 1.2 KB
/
google3.py
File metadata and controls
31 lines (29 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys,os
import urllib,re
import urllib.request
if __name__ == '__main__':
print (u'谷歌host修改脚本\nauthor pop<hipop#126.com>\n01/05/015\r数据:http://www.360kb.com/kb/2_122.html')
#load host from 360kb
htmlH = urllib.request.urlopen('http://www.360kb.com/kb/2_122.html')
html = htmlH.read().decode()
reg = r'#base services.*#google hosts 2015 end'
hostHtmlRe = re.search(reg, html, re.S)
hostHtml = hostHtmlRe.group()
hostHtml = hostHtml.replace(' ',' ')
hostHtml = hostHtml.replace('<span>', '')
hostHtml = hostHtml.replace('</span>', '')
hostStr = hostHtml.replace('<br />','')
#write host file
f = open('C:\\Windows\\System32\\drivers\\etc\\hosts', 'r+')
hostOld = f.read()
reg = re.compile(r'\r\n#google=.*#google hosts 2015 end', re.S)
hostNew = re.sub(reg, '', hostOld)
hostNew = hostNew + '\r\n#google===========================\r\n' + hostStr
#安全起见,不修改account相关
reg = re.compile(r'account', re.S)
hostNew = re.sub(reg, 'OOXXaccount', hostNew)
print (hostNew)
f.seek(0)
f.write(hostNew)
f.close()
print ('ok')