So I wrote a batch file t's purpose is to check the following:
1. is IP replying or not.
2. is destination reachable or not.
3. is connection timed out or not.
4. some other error.
@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 therError )
)
)
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 )
therError
echo Some Other Error >> Result.txt
GOTO End
:End
pause
Now i'm confused about the printing order of the things. I mean if the destination is unreachable then it's understood that connection is timed out and ip is not replying. Did I do this correctly and is there a easier way to do this because I think I made it a bit complex.
1. is IP replying or not.
2. is destination reachable or not.
3. is connection timed out or not.
4. some other error.
@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 therError )
)
)
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 )
therError
echo Some Other Error >> Result.txt
GOTO End
:End
pause
Now i'm confused about the printing order of the things. I mean if the destination is unreachable then it's understood that connection is timed out and ip is not replying. Did I do this correctly and is there a easier way to do this because I think I made it a bit complex.