; ********* YOUR CODE STARTS HERE *********
Dim $strHost,$strHostList,$iResponse
$strHostList="COMPUTER1 COMPUTER2.COMPANY.COM 127.0.0.1"
For Each $strHost in Split($strHostList)
$iResponse=wmiPing($strHost)
If @ERROR
"Error pinging "+$strHost+", reason code ["+@ERROR+"] "+udfPingStatus(@ERROR)+@CRLF
Else
"Host "+$strHost+" is up, response time is "+$iResponse+@CRLF
EndIf
Next
; ********* YOUR CODE ENDS HERE *********
; -------------------------------------------------------------------------
; ********* PAY NO ATTENTION TO THE FUNCTIONS BEHIND THE CURTAIN **********
; -------------------------------------------------------------------------
;FUNCTION wmiPing()
;
;ACTION:
; Ping an IP-address/name and return the responsetime in msecs.
;
;AUTHORs:
; KHOLM
; Jooel
; Fixes by Richard H.
;
;VERSION:
; 1.1-rh
;
;DATE CREATED:
; 11 Dec 2006
;
;REVISION HISTORY:
; Original release from 2004 can be found here
;
; 20091002 Richard Howarth <rhowarth@harsco.com>
; Fixed handling of NULL status code.
; Explicitly return success
; Set error is no responses found
; UDF now explicitly exits on first result
; Assume NULL is a hostname lookup failure
;
;KIXTART:
; 4.22
;
;SYNTAX;
; wmiPing($Address[,$Timeout [,$BlockSize]])
;
;PARAMETERS:
; $Address: Name and IP-address of target to ping
; $Timeout: Optional, max waittime for reply in msecs. Default is 1000
; $BlockSize: Optional, size of send/recieve block in bytes. Default is 32
;
;RETURNS:
; Time of response in msecs if successfull
; otherwise @error is set to statuscode.
;
;DEPENDENCIES:
; Windows XP or Server 2003
;
;EXAMPLE:
; $Add = '195.140.240.55' ; Same as $Add = 'kixtart.org'
; $Res = wmiPing($Add,5000)
; If @Error
; ? 'No response from: ' + $Add
; Else
; ? 'Responsetime for: ' + $Add + ' is ' + $Res + ' ms'
; EndIf
;
;SOURCE:
Function wmiPing($Address,Optional $Timeout,Optional $BlockSize)
Dim $Query,$oWMI,$oItem,$cItems
$Query = "Select ResponseTime,StatusCode From Win32_PingStatus Where Address='" + $Address + "'"
If $Timeout $Query = $Query + " And TimeOut=" + $Timeout EndIf
If $BlockSize $Query = $Query + " And BufferSize=" + $BlockSize EndIf
$oWMI = GetObject("winmgmts:root\cimv2")
$cItems = $oWMI.ExecQuery($Query)
For Each $oItem In $cItems
If VarType($oItem.StatusCode) > 1
If $oItem.StatusCode
Exit $oItem.StatusCode
Else
$wmiPing = $oItem.ResponseTime
Exit 0
EndIf
Else
Exit 8524 ; Dummy exit value for NULL status, most descriptive (DNS lookup failure)
EndIf
Next
Exit 11050
EndFunction
Function udfPingStatus($ERROR,Optional $SERROR)
If Not VarName($SERROR) $SERROR="Unrecognised error code" EndIf
$udfPingStatus=$SERROR
Select
Case $Error="8524" $udfPingStatus="NULL result - probable host name lookup failure"
Case $Error="11001" $udfPingStatus="Buffer Too Small"
Case $Error="11002" $udfPingStatus="Destination Net Unreachable"
Case $Error="11003" $udfPingStatus="Destination Host Unreachable"
Case $Error="11004" $udfPingStatus="Destination Protocol Unreachable"
Case $Error="11005" $udfPingStatus="Destination Port Unreachable"
Case $Error="11006" $udfPingStatus="No Resources"
Case $Error="11007" $udfPingStatus="Bad Option"
Case $Error="11008" $udfPingStatus="Hardware Error"
Case $Error="11009" $udfPingStatus="Packet Too Big"
Case $Error="11010" $udfPingStatus="Request Timed Out"
Case $Error="11011" $udfPingStatus="Bad Request"
Case $Error="11012" $udfPingStatus="Bad Route"
Case $Error="11013" $udfPingStatus="TimeToLive Expired Transit"
Case $Error="11014" $udfPingStatus="TimeToLive Expired Reassembly"
Case $Error="11015" $udfPingStatus="Parameter Problem"
Case $Error="11016" $udfPingStatus="Source Quench"
Case $Error="11017" $udfPingStatus="Option Too Big"
Case $Error="11018" $udfPingStatus="Bad Destination"
Case $Error="11032" $udfPingStatus="Negotiating IPSEC"
Case $Error="11050" $udfPingStatus="General Failure"
EndSelect
EndFunction