Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

ntp.vbs - vbscript script by ActiveXperts Software

ntp.vbs queries a time server.

Use ntp.vbs directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select ntp.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.


ntp.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 = CheckNtp( "ntp.activexperts-labs.com" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"

Function CheckNtp( strHost )
' Description: 
'     Query a time server.
'     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 - Specifies the remote NTP server
' Usage:
'     CheckNtp( "<Hostname | IP>" )
' Sample:
'     CheckNtp( "ntp.activexperts-labs.com" )

  Dim objNtp

  CheckNtp             = retvalUnknown  ' Default return value
  SYSDATA              = ""             ' Not used by this function
  SYSEXPLANATION       = ""             ' Set initial value

  Set objNtp           = CreateObject( "AxNetwork.Ntp" )

  objNtp.GetTime strHost 
  If objNtp.LastError <> 0 Then
    CheckNtp          = False
    SYSEXPLANATION    = "Error #" & objNtp.LastError & ": " & objNtp.GetErrorDescription( objNtp.LastError )
    Exit Function
  End If

  CheckNtp             = True
  SYSEXPLANATION       = "NTP server queried, result=" & DateSerial ( objNtp.Year, objNtp.Month, objNtp.Day ) & " " & TimeSerial ( objNtp.Hour, objNtp.Minute, objNtp.Second ) & "; time-difference: "  & objNtp.LocalOffsetSeconds & " seconds"

End Function