Skip to content

Instantly share code, notes, and snippets.

@huxingyi huxingyi/auto_hosts.bat
Last active Dec 15, 2015

Embed
What would you like to do?
自动更新hosts,防ip被屏蔽,如果网络不通,会不断下载(间隔5秒左右),下载完成后,会对比hosts是否已修改(主要是为了使用SSD硬盘的考虑),如果已修改则更新到hosts。可以设为开机启动。
@set hosts_path=%systemroot%\System32\drivers\etc\hosts
@set tmp_path=new_hosts
@set hosts_url=https://smarthosts.googlecode.com/svn/trunk/hosts
@:retry
@wget "%hosts_url%" --no-check-certificate -O "%tmp_path%"
@if %errorlevel%==0 goto update
@ping 127.0.0.1 -n 5 -w 1000 > nul
@goto retry
@:update
@fc %hosts_path% %tmp_path%
@if %errorlevel%==0 goto exit
@type "%tmp_path%">"%hosts_path%"
@if %errorlevel%==0 goto exit
@attrib "%hosts_path%" -h -r -s
@ping 127.0.0.1 -n 5 -w 1000 > nul
@goto retry
@:exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.