别再老上网了,上网,[Python]代码#-
别再老上网了,上网,[Python]代码#-
[Python]代码
#-*- coding: cp936 -*-import os,sys#host file pathhost_path = os.environ.get('SYSTEMROOT',r'C:\Windows') + r'\system32\drivers\etc\hosts'#filter urlsfilter_urls = ['www.xiaonei.com','www.renren.com','www.oschina.com','www.weibo.com']def CNMode(): add_filter = '' f = open(host_path,'r+') fread = f.read() for f_url in filter_urls: if f_url not in fread:add_filter += '127.0.0.1 ' + f_url + '\n' try: f.write(add_filter) print "Change to CN mode successfully!" except: print "open file error!" finally: f.close()def FreeMode(): f = open(host_path,'r+') unremove = '' try: for line in f.readlines(): if line.split()[-1] not in filter_urls:unremove += line f.close() f = open(host_path,'w') f.write(unremove) print "Change to free mode successfully!" except: print "open file error!" finally: f.close()if __name__ == "__main__": if len(sys.argv) == 2 and sys.argv[1].upper() == 'CN': CNMode() elif len(sys.argv) == 2 and sys.argv[1].upper() == 'FREE': FreeMode() else: print """para is error!such as: python host.py cn ;or: python host.py free!"""
相关内容
- makeNumPwd,,[Python]代码de
- 根据规则生成随机密码,规则生成随机密码,[Python]代码
- 谷歌搜索,,[Python]代码#!
- 统计代码行数,代码行数,TotalLine.py
- Python计算自然周和自然月的首日时间戳,python首日,因工
- python SSH暴力破解工具,pythonssh暴力破解,[Python]代码#!
- 一个用Python给Vim做的插件,PythonVim做插件,function! Go
- Python登录人人网并抓取新鲜事,python新鲜事,Python登录人
- python计算对角线有理函数插值,python对角线插值,''' p
- 练习python,,[Python]代码de
评论关闭