|
运用windows批处理实现一键科学上网io7免费翻墙网
io7免费翻墙网
@echo offio7免费翻墙网
if defined converted goto :convertedio7免费翻墙网
io7免费翻墙网
set ConverterPath=%temp%\HostsGeter_CodeConverter.vbsio7免费翻墙网
set ConverterOutput=%temp%\HostsGeter_GBK.batio7免费翻墙网
io7免费翻墙网
echo inputpath="%~0" >%ConverterPath%io7免费翻墙网
echo outputpath="%ConverterOutput%" >>%ConverterPath%io7免费翻墙网
echo set stm2=createobject("ADODB.Stream") >>%ConverterPath%io7免费翻墙网
echo stm2.Charset ="utf-8" >>%ConverterPath%io7免费翻墙网
echo stm2.Open >>%ConverterPath%io7免费翻墙网
echo stm2.LoadFromFile inputpath >>%ConverterPath%io7免费翻墙网
echo readfile = stm2.ReadText >>%ConverterPath%io7免费翻墙网
echo stm2.Close >>%ConverterPath%io7免费翻墙网
echo Set Stm1 =CreateObject("ADODB.Stream") >>%ConverterPath%io7免费翻墙网
echo Stm1.Type = 2 >>%ConverterPath%io7免费翻墙网
echo Stm1.Open >>%ConverterPath%io7免费翻墙网
echo Stm1.Charset ="GBK" >>%ConverterPath%io7免费翻墙网
echo Stm1.Position = Stm1.Size >>%ConverterPath%io7免费翻墙网
echo Stm1.WriteText "set converted=y" ^& vbcrlf >>%ConverterPath%io7免费翻墙网
echo Stm1.WriteText readfile >>%ConverterPath%io7免费翻墙网
echo Stm1.SaveToFile outputpath,2 >>%ConverterPath%io7免费翻墙网
echo Stm1.Close >>%ConverterPath%io7免费翻墙网
%ConverterPath% && %ConverterOutput%io7免费翻墙网
goto :eofio7免费翻墙网
io7免费翻墙网
:convertedio7免费翻墙网
io7免费翻墙网
chcp 936io7免费翻墙网
:: 更改cmd窗口代码页至 936(GBK)io7免费翻墙网
io7免费翻墙网
clsio7免费翻墙网
%1 %2io7免费翻墙网
ver|find " 5.">nul &&goto :stio7免费翻墙网
echo 正在进行 UAC 提权...io7免费翻墙网
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :st","","runas",1)(window.close)&goto :eofio7免费翻墙网
:stio7免费翻墙网
io7免费翻墙网
clsio7免费翻墙网
io7免费翻墙网
@REM HostsGet Version0.4io7免费翻墙网
cd /d %~dp0io7免费翻墙网
io7免费翻墙网
set LogFilePath=%temp%\HostsGeter_log.txtio7免费翻墙网
set DLScriptPath=%temp%\downloadhosts.vbsio7免费翻墙网
set DLPath=%windir%\system32\drivers\etc\hosts_downloadedio7免费翻墙网
set BackupDir=%windir%\system32\drivers\etcio7免费翻墙网
set HostsPath=%windir%\system32\drivers\etc\hostsio7免费翻墙网
io7免费翻墙网
set LogToFile=^>^>%LogFilePath% 2^>^&1io7免费翻墙网
set EchoAndLog=call :echoandlogio7免费翻墙网
echo. %LogToFile%io7免费翻墙网
echo ==========[%date% %time%]========== %LogToFile%io7免费翻墙网
echo 日志文件:io7免费翻墙网
echo %LogFilePath%io7免费翻墙网
echo.io7免费翻墙网
io7免费翻墙网
echo iLocal=LCase("%DLPath%") > %DLScriptPath% ||(io7免费翻墙网
call :error downloadhosts.vbs 文件创建/写入失败.io7免费翻墙网
)io7免费翻墙网
echo iRemote=LCase("https://coding.net/u/scaffrey/p/hosts/git/raw/master/hosts") >> %DLScriptPath%io7免费翻墙网
echo Set xPost=createObject("Microsoft.XMLHTTP") 'Set Post = CreateObject("Msxml2.XMLHTTP") >> %DLScriptPath%io7免费翻墙网
echo xPost.Open "GET",iRemote,0 >> %DLScriptPath%io7免费翻墙网
echo xPost.Send() >> %DLScriptPath%io7免费翻墙网
echo set sGet=createObject("ADODB.Stream") >> %DLScriptPath%io7免费翻墙网
echo sGet.Mode=3 >> %DLScriptPath%io7免费翻墙网
echo sGet.Type=1 >> %DLScriptPath%io7免费翻墙网
echo sGet.Open() >> %DLScriptPath%io7免费翻墙网
echo sGet.Write xPost.ResponseBody >> %DLScriptPath%io7免费翻墙网
echo sGet.SaveToFile iLocal,2 >> %DLScriptPath%io7免费翻墙网
io7免费翻墙网
%EchoAndLog% 开始从 GitHub 中下载 hosts 文件...io7免费翻墙网
if exist %DLPath% del %DLPath% /s /q %LogToFile%io7免费翻墙网
%DLScriptPath% || call :error hosts 文件下载失败.io7免费翻墙网
del %DLScriptPath% /s /q %LogToFile%io7免费翻墙网
if not exist %DLPath% call :error hosts 文件下载失败.io7免费翻墙网
%EchoAndLog% 下载完成.io7免费翻墙网
echo.io7免费翻墙网
io7免费翻墙网
if exist %HostsPath% (io7免费翻墙网
call :backuphostsio7免费翻墙网
) else (io7免费翻墙网
%EchoAndLog% (原 hosts 文件不存在,跳过备份)io7免费翻墙网
)io7免费翻墙网
%EchoAndLog% 正在替换 hosts 文件...io7免费翻墙网
move %DLPath% %HostsPath% %LogToFile% || call :error hosts 文件替换失败.io7免费翻墙网
%EchoAndLog% hosts 文件已替换.io7免费翻墙网
echo.io7免费翻墙网
io7免费翻墙网
%EchoAndLog% 正在刷新系统 DNS 缓存...io7免费翻墙网
ipconfig /flushdns %LogToFile% || call :error DNS 缓存刷新失败.io7免费翻墙网
%EchoAndLog% DNS 缓存已刷新.io7免费翻墙网
echo.io7免费翻墙网
%EchoAndLog% 【操作全部完成!】io7免费翻墙网
echo.io7免费翻墙网
io7免费翻墙网
echo 按任意键访问 google.com.hk 进行测试,如取消,请直接关闭本窗口io7免费翻墙网
pause >nulio7免费翻墙网
start https://www.google.com.hkio7免费翻墙网
echo 已经帮你访问 google.com.hk 如可以访问则替换成功.io7免费翻墙网
echo.io7免费翻墙网
goto :endio7免费翻墙网
io7免费翻墙网
:backuphostsio7免费翻墙网
%EchoAndLog% 正在备份原 hosts 文件...io7免费翻墙网
set "bakfilename=hosts_%date%_%time:~0,8%.bak"io7免费翻墙网
set bakfilename=%bakfilename:/=-%io7免费翻墙网
set bakfilename=%bakfilename:\=-%io7免费翻墙网
set bakfilename=%bakfilename::=-%io7免费翻墙网
set bakfilename=%bakfilename: =_%io7免费翻墙网
copy %HostsPath% %BackupDir%\%bakfilename% %LogToFile% || call :error hosts 文件备份失败.io7免费翻墙网
%EchoAndLog% 原 hosts 文件已备份到 %BackupDir%\%bakfilename%.io7免费翻墙网
echo.io7免费翻墙网
goto :eofio7免费翻墙网
io7免费翻墙网
:errorio7免费翻墙网
echo ======================io7免费翻墙网
%EchoAndLog% 错误:%*io7免费翻墙网
start %LogFilePath%io7免费翻墙网
echo 已打开日志文件io7免费翻墙网
goto :endio7免费翻墙网
io7免费翻墙网
:echoandlogio7免费翻墙网
echo %*io7免费翻墙网
echo %* %LogToFile%io7免费翻墙网
goto :eofio7免费翻墙网
io7免费翻墙网
:endio7免费翻墙网
echo 按任意键关闭io7免费翻墙网
pause >nulio7免费翻墙网
exitio7免费翻墙网
io7免费翻墙网
|