Tag:windows batch processing
@echo off &setlocal enabledelayedexpansionecho Modify the Hosts file:: type c:\windows\ system32\drivers\etc\hosts^ | findstr /n ". *": mainecho ======================== =======echo Select the action echo ===============================echo.echo 1 you want to make. Add hosts 2. Modify hostsecho.echo 3. empty hosts 4. Show current hosts content echo.echo 5. exit 6. Clear Screen choice /c:123456 /m: Please enter a number: 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= Please enter the domain name: echo -------------------------------set /p ip= Please enter ip:echo -------------------------- -----echo %ip% %domain% >>c:\windows\system32\drivers\etc\hostsif errorlevel 0 (echo modified successfully) else (echo modification failed) choice /c:123 /m:1 back, 2ping test, 3 exit:if Errorlevel 3 goto endif errorlevel 2 goto pingif errorlevel 1 goto main:pingecho ----------------Start the ping test----------------for /f "delims=[] tokens=2 " %%i in (' ping -n 1 %domain%^|findstr [') do (if %ip% == %%i (echo ----------------Ping Test successfully----------------) else (Echo ----------------Ping test failed, please re-modify----------------)) goto choice:typeecho Current hosts content: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 cleared successfully) else (echo cleanup failed) type nul >c:\windows\system32\drivers\etc\hostsgoto choice:choicechoice /c:12 /m: Continue, press 1 , exit please press 2rem should first determine the highest value error code If errorlevel 2 goto endif errorlevel 1 goto main:endexit
This article from "Day Up" blog, please be sure to keep this source http://bshark.blog.51cto.com/10309374/1934401
Windows Batch processing small note