標籤:windows 批處理
@echo off &setlocal enabledelayedexpansionecho 修改hosts檔案::type c:\windows\system32\drivers\etc\hosts^ | findstr /n ".*":mainecho ===============================echo 請選擇需要進行的操作echo ===============================echo.echo 1. 添加hosts 2. 修改hostsecho.echo 3. 清空hosts 4. 顯示當前hosts內容echo.echo 5. 退出 6. 清屏 choice /c:123456 /m:請輸入數字:if errorlevel 6 goto clearif errorlevel 5 goto endif errorlevel 4 goto typeif errorlevel 3 goto delif errorlevel 2 goto changeif errorlevel 1 goto add:addecho -------------------------------set /p domain=請輸入欄位名:echo -------------------------------set /p ip=請輸入IP:echo -------------------------------echo %ip% %domain% >>c:\windows\system32\drivers\etc\hostsif errorlevel 0 (echo 修改成功) else (echo 修改失敗)choice /c:123 /m:1返回,2ping測試,3退出:if errorlevel 3 goto endif errorlevel 2 goto pingif errorlevel 1 goto main:pingecho ----------------開始進行ping測試----------------for /f "delims=[] tokens=2 " %%i in (‘ping -n 1 %domain%^|findstr [‘) do (if %ip% == %%i (echo ----------------ping測試成功----------------) else (echo ----------------ping測試失敗,請重新修改----------------))goto choice:typeecho 當前hosts內容:echo -------------------------------type c:\windows\system32\drivers\etc\hosts^ | findstr /n ".*"echo -------------------------------echo.goto choice:clearclsgoto main:deldel /Q c:\windows\system32\drivers\etc\hostsif errorlevel 0 (echo 清除成功) else (echo 清除失敗)type nul >c:\windows\system32\drivers\etc\hostsgoto choice:choicechoice /c:12 /m:繼續請按1,退出請按2REM 應先判斷數值最高的錯誤碼if errorlevel 2 goto endif errorlevel 1 goto main:endexit
本文出自 “天天向上” 部落格,請務必保留此出處http://bshark.blog.51cto.com/10309374/1934401
windows 批處理小記