Skip to content

Instantly share code, notes, and snippets.

@mark05e
Created July 10, 2022 20:00
Show Gist options
  • Save mark05e/03c12939b0de7b9c8514a0d13f6682d0 to your computer and use it in GitHub Desktop.
Save mark05e/03c12939b0de7b9c8514a0d13f6682d0 to your computer and use it in GitHub Desktop.
@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