ping.vbs - vbscript script by ActiveXperts Software
ping.vbs pings a remote host.
Use ping.vbs directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select ping.vbs. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
ping.vbs script code
' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor - VBScript based checks
' // For more information about ActiveXperts Network Monitor and VBScript, visit
' // http://www.activexperts.com/support/network-monitor/online/vbscript/
' ///////////////////////////////////////////////////////////////////////////////
Option Explicit
' Declaration of global variables
Dim SYSDATA, SYSEXPLANATION ' SYSDATA is displayed in the 'Data' column in the Manager; SYSEXPLANATION in the 'LastResponse' column
' Constants - return values
Const retvalUnknown = 1 ' ActiveXperts Network Monitor functions should always return True (-1, Success), False (0, Error) or retvalUnknown (1, Uncertain)
' // To test a function outside Network Monitor (e.g. using CSCRIPT from the
' // command line), remove the comment character (') in the following lines:
' Dim bResult
' bResult = Ping( "www.activexperts.com", 160 )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
Function Ping( strHost, nMaxTimeout )
' Description:
' Ping a remote host.
' This function uses ActiveXperts Network Component.
' ActiveXperts Network Component is automatically licensed when ActiveXperts Network Monitor is purchased
' For more information about ActiveXperts Network Component, see: www.activexperts.com/network-component
' Parameters:
' 1) strHost As String - Hostname or IP address of the computer you want to ping
' 2) nmaxTimeOut - Timeout in milliseconds
' Usage:
' Ping( "<Hostname | IP>", <Timeout_MSecs> )
' Sample:
' Ping( "www.activexperts.com", 160 )
Dim objIcmp
Ping = retvalUnknown ' Default return value
SYSDATA = "" ' Will hold the response time in milliseconds
SYSEXPLANATION = "" ' Set initial value
Set objIcmp = CreateObject( "AxNetwork.Icmp" )
objIcmp.Ping strHost, 3000 ' Maximum. timeout: 3000 ms
If( objIcmp.LastError <> 0 ) Then
Ping = False
SYSDATA = ""
SYSEXPLANATION = objIcmp.GetErrorDescription( objIcmp.LastError )
Exit Function
End If
If( objIcmp.LastDuration > nMaxTimeout ) Then
Ping = False
SYSDATA = objIcmp.LastDuration
SYSEXPLANATION = "Request from [" & strHost & "] timed out, time=[" & objIcmp.LastDuration & "ms] (>" & nMaxTimeOut & "ms)"
Else
Ping = True
SYSDATA = objIcmp.LastDuration
SYSEXPLANATION = "Reply from " & strHost & ", time=[" & objIcmp.LastDuration & "ms], TTL=[" & objIcmp.LastTTL & "]"
End If
End Function
