@echo off setlocal EnableExtensions if "%~1"=="" goto usage set "host=%~1" set "count=%~2" if "%count%"=="" set "count=4" echo %host% | findstr /r /c:"^[A-Za-z0-9._:-]*$" >nul if errorlevel 1 ( echo Invalid host name. exit /b 2 ) echo %count% | findstr /r /c:"^[0-9][0-9]*$" >nul if errorlevel 1 ( echo Count must be a number. exit /b 2 ) if %count% LSS 1 ( echo Count must be at least 1. exit /b 2 ) if %count% GTR 100 ( echo Count must be 100 or less. exit /b 2 ) echo Pinging %host% %count% time(s) set /a received=0 for /l %%i in (1,1,%count%) do ( ping -n 1 -w 1000 %host% >nul if errorlevel 1 ( echo [!] Attempt %%i: no reply ) else ( set /a received+=1 echo [ok] Attempt %%i: reply ) ) echo Sent: %count%, received: %received% if %received%==0 exit /b 1 exit /b 0 :usage echo Usage: %~nx0 host [count] exit /b 2