回复 6# 北极奇熊
确保ip后面确实是两个空格(就如1楼那样)- @echo off
- set "HOSTS_FILE=%SystemRoot%\System32\drivers\etc\hosts"
- set "TEMP_FILE=%TEMP%\hosts.tmp"
-
- echo 正在处理hosts文件...
- (for /f "tokens=*" %%a in ('type "%HOSTS_FILE%"') do (
- set "line=%%a"
- call :CheckLine
- )) > "%TEMP_FILE%"
-
- echo 正在更新hosts文件...
- copy /y "%TEMP_FILE%" "%HOSTS_FILE%" >nul
- echo 完成!
- pause
- exit/b
-
- :CheckLine
- setlocal enabledelayedexpansion
- set "LINE_TO_CHECK=!line!"
- if "!LINE_TO_CHECK:~0,1!" == "#" echo:!LINE_TO_CHECK!&endlocal & goto :eof
- echo:!LINE_TO_CHECK!| findstr /i /c:"172.72.14.216 bj.ucam.cncc.cn" /c:"172.72.14.217 sh.ucam.cncc.cn" /c:"172.72.14.218 bj.coas.cncc.cn" >nul
- if errorlevel 1 (
- echo:!LINE_TO_CHECK!
- ) else (
- echo 删除行: !LINE_TO_CHECK! >con
- )
- endlocal & goto :eof
复制代码
|