Skip to content

Instantly share code, notes, and snippets.

@phy25
Created July 13, 2014 02:26
Show Gist options
  • Save phy25/edcf8d1e4aa1f887780d to your computer and use it in GitHub Desktop.
Save phy25/edcf8d1e4aa1f887780d to your computer and use it in GitHub Desktop.
一键加入单条 hosts 的 bat 文件
@echo off
set isexist=
set dir=%windir%\system32\drivers\etc\hosts
set domain=www.google.com.hk
set ip=203.208.45.206
ver|findstr "6\.[0-9]\.[0-9][0-9]*">nul&&(set isXPlevel=2&echo 请确认已经用管理员权限打开。按任意键开始增加 %domain% 解析到 %ip%。&pause>nul)
for /f %%i in ('findstr /i "%domain%" %dir%') do set isexist=1
if not defined isexist (@echo.>>%dir%&@echo %ip% %domain%>>%dir%&echo 已增加 %domain% 解析到 %ip%&echo Hosts 增加完成。按任意键退出。&pause>nul) else (echo %domain% 的解析已经存在,请手工修改地址。按任意键修改。&pause>nul &start notepad.exe %dir%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment