@Echo Off
Rem (c) http://sofnote.blogspot.com/
Set WAITTIME=60
Set CMDNAME=%~nx0
Set TARGET=%~nx1
If Not "%TARGET%"=="" Goto ARGS_OK
Echo.Usage:
Echo. %CMDNAME% (hostname ^| ip address)
Echo.or
Echo. drag [(hostname ^| ip address)] file icon to [%CMDNAME%] icon.
Goto ERROR
:ARGS_OK
Rem hostname check
Echo.executing: ping -n 1 %TARGET%...
Set LINES=0
For /F "tokens=*" %%i In ('ping -n 1 %TARGET%') Do Call :PING_ERR_CHECK ".%%i"
If Not %LINES%==1 Goto HOSTNAME_OK
Goto ERROR
:HOSTNAME_OK
If %LINES%==9 Goto SUCCESS
ping localhost -n %WAITTIME% > nul
:RETRY
Echo.executing: ping -n 1 %TARGET%...
ping -n 1 %TARGET%
if Not ERRORLEVEL 1 Goto PINGABLE
ping localhost -n %WAITTIME% > nul
Goto RETRY
:PINGABLE
:SUCCESS
Pause
Exit /b 0
:ERROR
Pause
Exit /b 1
Rem Return values:
Rem LINES: number of line which ping result
:PING_ERR_CHECK
Setlocal ENABLEDELAYEDEXPANSION
Set MSG=%1
For /F "tokens=*" %%i In (!MSG!) Do Echo%%~i
Endlocal
Set /A LINES=%LINES%+1
Exit /b 0