Option Explicit
dim blnPinged, strHost
strHost="www.google.com" ' Change the address to where you want to ping
blnPinged=true
while blnPinged ' Loop while ping is successful
blnPinged=Ping(strHost)
if blnPinged then
wscript.echo "Pinged " & strHost & " successfully at " & Now
WScript.Sleep 1000 ' 1000 is one second, adjust accordingly
else
wscript.echo "Ping failed to " & strHost & " at " & Now
end if
wend
Function Ping(strHost)
dim objPing, objRetStatus
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")
for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
else
Ping = True
end if
next
End Function
|