python脚本语言实现hosts自动更新
来源:互联网 发布:microsoft word mac 编辑:程序博客网 时间:2024/06/01 09:01
python脚本语言实现hosts自动更新
最近在逛github的时候发现有人在更新hosts,于是作为一个拿来主义的人,我就写了一个脚本来自动更新hosts
原料
- 工具 python.exe环境
- github_hosts更新的网址
更新原理
python脚本访问github 如:https://raw.githubusercontent.com/liuker0x007/hosts/master/hosts
在通过urlopen()函数后获取的字符流后写入本地的文件:C:\Windows\System32\drivers\etc\hosts
代码块
代码块语法遵循标准markdown代码,例如:
“` python
@requires_authorization
import re
import urllib2
import os
import sys
command=’ipconfig /flushdns’
url=”https://raw.githubusercontent.com/liuker0x007/hosts/master/hosts”
hostsurl=”C:\Windows\System32\drivers\etc\hosts”
try:
web=urllib2.urlopen(url)
print u”正在从服务器更新Hosts文件………..”
webbuff=web.read()
f=open(hostsurl,”w”)
if f!=None:
print u”正在写入Hosts文件……………….”
f.write(webbuff)
print u”刷新本地DNS…………………….”
os.system(command)
f.flush()
f.close()
os.system(“pause”)
else:
print u’请提供管理员权限’
except:
print u”请检查网络连接/提供管理员权限”
sys.exit(0)
finally:
sys.exit(0)
需要以管理员方式运行脚本
- python脚本语言实现hosts自动更新
- 自动更新hosts.bat
- huhamhire-hosts自动更新Google Hosts文件教程
- 使用python脚本语言实现快速打包
- python脚本语言
- python脚本语言
- python--脚本语言
- python脚本语言
- 使用Python脚本语言实现自动多渠道打包心得
- python+迅雷实现自动更新Symantec的病毒定义
- Python+Git+FTP实现内部分发网站数据的自动更新
- 从零开始学习Python脚本语言
- Python脚本语言简介
- python 脚本语言1
- python脚本语言2
- python脚本语言3
- 自动化测试-python脚本语言
- MFC 使用Python脚本语言
- 使C# 窗体的关闭按钮、最小化、最大化按钮不可用
- HPU 问题 G: 感恩节KK专场——与学妹滑雪 【最短路 double 精度判断】
- windows下安装redis
- 数据结构——二叉树 前序、中序、后序、层次遍历及非递归实现 查找、统计个数、比较、求深度的递归实现
- C++Builder 自定义消息 处理
- python脚本语言实现hosts自动更新
- 关于vi的三种模式的常用命令
- Android软键盘的隐藏显示研究
- maven父子项目
- Ubuntu修改hosts方法
- 关于U-boot的移植(一)
- 第一篇记录:
- iOS AutoLayout自动布局中级开发教程(4)-label等文字自动适应大小,宽度
- 阿里云服务器搭建之绑定多个域名