功能:屏蔽一些网站访问,1小时后恢复
如需修改屏蔽时间,可以修改hourly那一行
:: 关闭全部回显
@echo off
:: 获取管理员权限(方法1):https://www.cnblogs.com/conducer/p/10591614.html
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
:: 注:等号前后不能有空格!
set hosts=%windir%\System32\drivers\etc\hosts
set hosts_bk=%windir%\System32\drivers\etc\hosts_bk
set temp_hosts=%windir%\System32\drivers\etc\hosts_temp
:: 注:%temp%在不同账户下不同!比如在schtasks里使用SYSTEM账户运行时就不是
set flag_file=%temp%\unban.flag
:: 1. 直接运行时(flag文件还不存在):屏蔽网站,备份Hosts
:: 注意:if else
if not exist %flag_file% (
:: 备份Hosts
:: >nul 2>nul用于屏蔽打印的结果
copy>nul 2>nul %hosts% %hosts_bk%
:: 因为无法直接修改,只能采用建另一个文件再覆盖hosts的方式
echo 127.0.0.1 www.bilibili.com >> %temp_hosts%
echo 127.0.0.1 live.bilibili.com >> %temp_hosts%
echo 127.0.0.1 www.lofter.com >> %temp_hosts%
echo 127.0.0.1 www.weibo.com >> %temp_hosts%
echo 127.0.0.1 passport.weibo.com >> %temp_hosts%
echo 127.0.0.1 s.weibo.com >> %temp_hosts%
echo 127.0.0.1 weibo.com >> %temp_hosts%
echo 127.0.0.1 www.douban.com >> %temp_hosts%
echo 127.0.0.1 www.taobao.com >> %temp_hosts%
echo 127.0.0.1 www.tmall.com >> %temp_hosts%
copy>nul 2>nul %temp_hosts% %hosts%
:: 创建计划任务,mo为频率
:: 此处使用%USERNAME%是因为,如果用SYSTEM会导致%temp%与双击执行bat时的%temp%不同(用户不同)
schtasks>nul 2>nul /create /tn "unban_bat" /ru %USERNAME% /sc hourly /mo 1 /tr "%~0"
:: 用于判断的flag文件
echo > %flag_file%
) else (
:: 2. 通过计划任务运行时(flag文件已创建):还原Hosts,删除备份文件,删除计划任务
copy>nul 2>nul %hosts_bk% %hosts%
del %hosts_bk%
del %temp_hosts%
:: /f是强制删除无提示
schtasks>nul 2>nul /delete /tn "unban_bat" /f
:: 删除用于判断的flag文件
del %flag_file%
echo 屏蔽已解除
pause
)
:: 刷新
ipconfig /flushdns
:: del %0
不过这个容易绕过……用科学上网工具比如SS就可以绕过了
网友评论