Created
July 10, 2022 20:00
-
-
Save mark05e/03c12939b0de7b9c8514a0d13f6682d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
REM https://stackoverflow.com/questions/56928545/how-to-make-a-batch-file-react-differently-based-on-the-success-percent-of-a-pin | |
REM Ben Personick | |
@( | |
SetLocal EnableDelayedExpansion | |
ECHO OFF | |
SET "_PingAddress=www.aol.com" | |
SET "_Count=0" | |
) | |
FOR /F "Tokens=1-2 Delims=[]" %%A IN ('Ping %_PingAddress%') DO ( | |
IF NOT DEFINED _IP ( | |
IF /I "%%B" NEQ "" ( | |
SET "_IP=%%B" | |
) ELSE ( | |
SET "_IP=%_PingAddress%" | |
) | |
) ELSE ( | |
ECHO.%%A | FIND /I "Reply From !_IP!" >nul && SET /A "_Count+=1" | |
) | |
) | |
IF /I %_Count% GTR 0 ( | |
ECHO Success - reached %_PingAddress% | |
REM More commands here | |
) ELSE ( | |
ECHO Failure - cannot reach %_PingAddress% | |
REM More commands here | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment