python check hosts update
来源:互联网 发布:stc单片机最小系统 编辑:程序博客网 时间:2024/05/22 15:59
用Python检查 hosts 更新
最近各种代理纷纷关闭,常见的翻墙方式就剩lantern和更改hosts的方式依旧坚挺,关注了一些更新hosts的git仓库,但是又不想登录网页查看原作者是否有更新。所以这种苦力活就让Python干好了。
hosts地址
hosts_info.py
hosts_source = ["https://raw.githubusercontent.com/racaljk/hosts/master/hosts"]
检查hosts是否有更新
check_hosts.py
import urllib2from .hosts_info import *import osimport filecmpdef hosts_download(): if os.path.exists('hosts'): hosts_name = 'hosts_new' else: hosts_name = 'hosts' # todo: overtime detection f = urllib2.urlopen(hosts_source[0]) print "downloading hosts" with open(hosts_name, "wb") as code: code.write(f.read())def is_hosts_new(): hosts_download() if not os.path.exists('hosts'): print 'oops, hosts not exists' return -1 elif os.path.exists('hosts') and (not os.path.exists('hosts_new')): print 'first run, only one hosts file' return True elif os.path.exists('hosts') and (os.path.exists('hosts_new')): print 'compare hosts & hosts_new' diff_status = filecmp.cmp('hosts', 'hosts_new') if diff_status: print 'same file' os.remove('hosts_new') return False else: print 'diff file' os.remove('hosts') os.rename('hosts_new', "hosts") return True else: return -1
主程序调用
main.py
from check_hosts.check_hosts import *diff_status = is_hosts_new()if diff_status: print "new hosts !"else: print 'code: ',diff_status
阅读全文
0 0
- python check hosts update
- del update check
- Eclipse Check for update 异常
- Android Studio check update失败
- Python更新hosts
- BAdi:BOM_UPDATE - Check update for BOM Save
- Android Studio Check for Update Connection failed
- python check syntax
- Python check passwd
- 更新hosts的python脚本
- python 更新谷歌hosts
- python脚本语言实现hosts自动更新
- 【Python】Python语言check list
- hosts
- hosts
- hosts
- hosts
- hosts
- MySQL 利用伪列优化多次使用order by
- 数据处理:12个使得效率倍增的pandas技巧
- Spring之AOP
- android webview图片文件上传兼容性问题——上传控件点击无效的解决办法
- 大数据(二)Hadoop安装环境搭建【安装Hadoop】
- python check hosts update
- 自然语言处理-分布表示
- 一分钟了解“比较时情态动词代替前述动词”
- SpringAOP配置声明式切面时报错error at ::0 formal unbound in pointcut
- 配置Asp.Net MVC WebAPI可跨域方法
- Python相关书籍
- 「ubuntu」在Ubuntu Server环境,使用开源软件ownCloud架设私有云网盘
- python mail sender
- ARP协议和RARP协议