@echo off
rem color 1f
set title=github下载加速[修改hosts]
title %title%
set "HOSTS_PATH=%windir%\system32\drivers\etc\hosts"REM 备份原始的 hosts 文件
copy "%HOSTS_PATH%" "%HOSTS_PATH%.bak"rem 使用 findstr 获取最后一行
set number=0
for /f "delims=" %%a in ('findstr /n .* "%HOSTS_PATH%"') do (
    set /a number+=1
    set "endline=%%a"
)
rem echo endline=%endline%
rem echo number=%number%if "%endline%"=="%number%:" (
    echo 最后一行不是空行。
) else (
    echo 最后一行是空行,插入一个空白行...
    echo.>>"%HOSTS_PATH%"
)rem 修改hosts:
attrib -s -h -r "%HOSTS_PATH%"
REM 使用 findstr 删除包含github.com和github.global.ssl.fastly.net的行
findstr /v /i "github.com github.global.ssl.fastly.net" "%HOSTS_PATH%" > "%HOSTS_PATH%.txt"
echo 140.82.114.4 github.com>>"%HOSTS_PATH%.txt"
echo 146.75.77.194 github.global.ssl.fastly.net>>"%HOSTS_PATH%.txt"
copy /y "%HOSTS_PATH%.txt"  "%HOSTS_PATH%"
del /f/q "%HOSTS_PATH%.txt"ipconfig /flushdns
echo 修改hosts完毕!:showhosts
notepad "%windir%\system32\drivers\etc\hosts"
rem pause 1>nul 2>nul
exit /b