Friday, March 09, 2007 9:05 AM
royashbrook
ping check - aka isup
@echo off
set a=1
ping -n 1 %1 | find /c "bytes=32" > nul
if %errorlevel% == 1 set a=0
echo %1 %a%
set a=
(via
don't feed the penguins)
*edit*
this is a very simple shell script that i used to use for ping checks. i found that it even outperformed using the wmi ping and several other mechanisms for pinging machines that i tried. i'm sure i could rant on at length about all of the times and ways that i had used it, but i won't. note that you could just look for 1 as an error and just use error level, i wanted to return 1 for up and 0 for down though so i had to put some logic to handle that.
function isup(strComputer)'ping check, modified to work on w2k and nt4
dim x
isup = 0
x = gco("ping -n 1 " & strComputer)
if ubound(x) >= 3 then
if instr(x(3),"bytes") then isup = 1
end if
end function
function gco(scommand)'get command output
dim sTempFile
sTempFile = fso.GetSpecialFolder(2).Path & "\" & fso.GetTempName
CreateObject("Wscript.Shell").Run "%COMSPEC% /c " & scommand & ">" & sTempFile, 0, True
gco = split(fso.OpenTextFile(sTempFile, 1).ReadAll,vbcrlf)
fso.DeleteFile sTempFile
end function
(via
don't feed the penguins)
*edit*
this is a very simple ping check for vbscript. it's basically the same thing as above, just in vbscript, not shell.
Filed under: scripting