1. If a particular IP address is replying or not.
2. If host is reachable or not.
3. If IP is timed out or not.
4. Some other error
Code: Select all
@echo off
set /p ip="Enter IP Address: "
ping %ip% -n 2 > nul > IP.txt
if %ERRORLEVEL% == 0 (
echo Ping To %ip% Successful > Result.txt
) else echo Ping To %ip% Failed > Result.txt
findstr /m "unreachable" IP.txt
set ur=%ERRORLEVEL%
findstr /m "timed out" IP.txt
set t=%ERRORLEVEL%
findstr /m "Reply" IP.txt
set r=%ERRORLEVEL%
echo %ur% >> Result.txt
echo %r% >> Result.txt
echo %t% >> Result.txt
if %ur%==1 (
if %r%==1 (
if %t%==1 ( CALL :otherError )
)
)
if %ur% == 1 ( echo Reachable >> Result.txt
if %t% == 1 ( echo Not Timed Out >> Result.txt
if %r% == 0 ( echo System Is Replying >> Result.txt
CALL :End ) else ( echo Not Replying >> Result.txt
CALL :End )
) else ( echo Timed Out >> Result.txt
CALL :End )
) else ( echo Unreachable >> Result.txt
CALL :End )
:otherError
echo Some Other Error >> Result.txt
GOTO End
:End
pause
However I'm confused about the sequence of things. I mean if a host is unreachable then it's obvious that ip is not replying and it is timed out right?
Just take a look and see if it is correct or not.