dns.vbs - vbscript script by ActiveXperts Software
dns.vbs query a DNS server, and check the response.
Use dns.vbs directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select dns.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.
dns.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 = CheckDns( "ns1.ascio.net", "em1.activexperts-labs.com", "212.97.55.136" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
Function CheckDns( strDnsServer, strHost, strExpectedValue )
' Description:
' Query a DNS server, and validate the response
' 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) strDnsServer - Host name or IP address of the (remote) DNS server
' 2) strHost - Hostname or domain to query
' 3) strExpectedValue - expected value
' Usage:
' CheckDns( "<Hostname | IP>", "<host>", "<expected value>" )
' Sample:
' CheckDns( "ns1.ascio.net", "em1.activexperts-labs.com", "212.97.55.136" )
Dim objDnsServer, objConstants, objDnsRecord, bMatched
CheckDns = retvalUnknown ' Default return value, and will be shown as a yellow (uncertain) icon in the Manager
SYSDATA = "" ' SYSDATA displayed in the 'Data' column in the Manager
SYSEXPLANATION = "" ' SYSEXPLANATION displayed in the 'LastResponse' column in the Manager
bMatched = False
' Create instance of SNMP object
Set objDnsServer = CreateObject( "AxNetwork.DnsServer" )
Set objConstants = CreateObject( "AxNetwork.NwConstants" )
' Lookup
objDnsServer.Server = strDnsServer
objDnsServer.Lookup strHost, objConstants.nwDNS_TYPE_A
If( objDnsServer.LastError <> 0 ) Then
SYSEXPLANATION = "Unable to lookup on DNS server [" & objDnsServer.Server & "]; error #" & objDnsServer.LastError & ": " & objDnsServer.GetErrorDescription( objDnsServer.LastError )
CheckDns = retvalUnknown
Exit Function
End If
Set objDnsRecord = objDnsServer.GetFirstRecord
On Error Resume Next
While ( objDnsServer.LastError = 0 )
If( UCase( objDnsRecord.Name ) = UCase( strHost ) ) Then
If( SYSDATA <> "" ) Then
SYSDATA = SYSDATA & "; "
End If
SYSDATA = SYSDATA & objDnsRecord.Address
If( UCase( objDnsRecord.Address ) = UCase( strExpectedValue ) ) Then
bMatched = True
End If
End If
Set objDnsRecord = objDnsServer.GetNextRecord
WEnd
On Error Goto 0
If( bMatched ) Then
CheckDns = True
SYSEXPLANATION = "Response matched; response = [" & SYSDATA & "]"
Else
CheckDns = True
SYSEXPLANATION = "Response did not match; response = [" & SYSDATA & "]"
End If
End Function
