Dhcp.vbs - Check DHCP scope through ActiveXperts Network Monitor
ActiveXperts Network Monitor ships with a powerful set of pre-defined checks. Each individual check has a static number of configuration items. To monitor other items, or to combine monitoring items, you can make use of custom VBScript checks.
Most of the built-in checks have a VBScript equivalent, implemented as a Function in a VBScript (.vbs) file. Out-of-the-box, each VBScript function monitors the same items as the built-in check. Feel free to modify a function. The VBScript check can be customized by editing the VBScript function.
To add a new VBScript-based DHCP monitoring check, do the following:
- On the 'Monitor menu', click 'New Monitoring Check (VBScript)'. The 'VBScript Check' dialog box appears;
- In the 'File selection box', select 'Dhcp.vbs';
- In the 'Function selection box', select 'CheckDhcpMaxInUse', 'CheckDhcpMaxOffered' or 'CheckDhcpMinAvailable';
- In the 'Function parameters group box' enter the required parameters. You can also load a working sample first by clicking on the 'Load a sample, click here' link.
To customize the above monitoring check, click on the 'Edit button' next to the 'File selection box'. Notepad will be launched. You can now make changes to the VBScript function(s).

Dhcp.vbs script source code
' /////////////////////////////////////////////////////////////////////////////// ' // ActiveXperts Network Monitor - VBScript based checks ' // (c) ActiveXperts Software B.V. ' // ' // For more information about ActiveXperts Network Monitor and VBScript, please ' // visit the online ActiveXperts Network Monitor VBScript Guidelines at: ' // https://www.activexperts.com/support/network-monitor/online/vbscript/ ' // ' /////////////////////////////////////////////////////////////////////////////// Option Explicit Const retvalUnknown = 1 Dim SYSDATA, SYSEXPLANATION ' Used by Network Monitor, don't change the names ' ////////////////////////////////////////////////////////////////////////////// ' // To test a function outside Network Monitor (e.g. using CSCRIPT from the ' // command line), remove the comment character (') in the following 5 lines: ' Dim bResult ' bResult = CheckSnmp( "localhost", "public", "1.3.6.1.2.1.1.5.0", "My Computer Name" ) ' WScript.Echo "Return value: [" & bResult & "]" ' WScript.Echo "SYSDATA: [" & SYSDATA & "]" ' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]" ' //////////////////////////////////////////////////////////////////////////////////////// Function CheckDhcpMaxInUse( strDhcpServer, strSubnet, numMaxAllowed ) ' Description: ' Check for maximum number of IP addresses in use. ' Requires SNMP running on the DHCP server and monitoring system. ' This function uses the Network Component, an ActiveXperts product. ' Network Component is automatically licensed when ActiveXperts Network Monitor is purchased ' For more information about Network Component, see: www.activexperts.com/network-component ' Parameters: ' 1) strDhcpServer - Host name or IP address of the DHCP server ' 2) strSubnet - Subnet. ' 3) numMaxAllowed - maxmimum number of IP addresses allows ' Usage: ' CheckDhcpMaxInUse( "<Hostname | IP>", "x.x.x.x", <maximum value> ) ' Sample: ' CheckDhcpMaxInUse( "localhost", "192.168.31.0", 200 ) Dim strOID CheckDhcpMaxInUse = retvalUnknown ' Default return value SYSDATA = "" ' Not used by this function SYSEXPLANATION = "" ' Set initial value strOID = "1.3.6.1.4.1.311.1.3.2.1.1.2." & strSubnet If( Not checkDhcpValue( strDhcpServer, strOID, SYSDATA, SYSEXPLANATION ) ) Then CheckDhcpMaxInUse = retvalUnknown Exit Function End If SYSEXPLANATION = "IP's in use: [" & SYSDATA & "]" If( CInt( SYSDATA ) <= CInt( numMaxAllowed ) ) Then CheckDhcpMaxInUse = True Else CheckDhcpMaxInUse = False End If End Function ' ////////////////////////////////////////////////////////////////////////////// Function CheckDhcpMaxOffered( strDhcpServer, strSubnet, numMaxAllowed ) ' Description: ' Check for maximum number of IP addresses offered ' Requires SNMP running on the DHCP server and monitoring system. ' This function uses the Network Component, an ActiveXperts product. ' Network Component is automatically licensed when ActiveXperts Network Monitor is purchased ' For more information about Network Component, see: www.activexperts.com/network-component ' Parameters: ' 1) strDhcpServer - Host name or IP address of the DHCP server ' 2) strSubnet - Subnet. ' 3) numMaxAllowed - maxmimum number of IP addresses allows ' Usage: ' CheckDhcpMaxOffered( "<Hostname | IP>", "x.x.x.x", <maximum value> ) ' Sample: ' CheckDhcpMaxOffered( "localhost", "192.168.31.0", 5 ) Dim strOID CheckDhcpMaxOffered = retvalUnknown ' Default return value SYSDATA = "" ' Not used by this function SYSEXPLANATION = "" ' Set initial value strOID = "1.3.6.1.4.1.311.1.3.2.1.1.4." & strSubnet If( Not checkDhcpValue( strDhcpServer, strOID, SYSDATA, SYSEXPLANATION ) ) Then CheckDhcpMaxOffered= retvalUnknown Exit Function End If SYSEXPLANATION = "IP's offered: [" & SYSDATA & "]" If( CInt( SYSDATA ) <= CInt( numMaxAllowed ) ) Then CheckDhcpMaxOffered = True Else CheckDhcpMaxOffered = False End If End Function ' ////////////////////////////////////////////////////////////////////////////// Function CheckDhcpMinAvailable( strDhcpServer, strSubnet, numMinAvailable ) ' Description: ' Check for minimum number of IP addresses available. ' Requires SNMP running on the DHCP server and monitoring system. ' This function uses the Network Component, an ActiveXperts product. ' Network Component is automatically licensed when ActiveXperts Network Monitor is purchased ' For more information about Network Component, see: www.activexperts.com/network-component ' Parameters: ' 1) strDhcpServer - Host name or IP address of the DHCP server ' 2) strSubnet - Subnet. ' 3) numMaxAllowed - maxmimum number of IP addresses allows ' Usage: ' CheckDhcpMinAvailable( "<Hostname | IP>", "x.x.x.x", <maximum value> ) ' Sample: ' CheckDhcpMinAvailable( "localhost", "192.168.31.0", 10 ) Dim strOID CheckDhcpMinAvailable = retvalUnknown ' Default return value SYSDATA = "" ' Not used by this function SYSEXPLANATION = "" ' Set initial value strOID = "1.3.6.1.4.1.311.1.3.2.1.1.3." & strSubnet If( Not checkDhcpValue( strDhcpServer, strOID, SYSDATA, SYSEXPLANATION ) ) Then CheckDhcpMinAvailable = retvalUnknown Exit Function End If SYSEXPLANATION = "IP's available: [" & SYSDATA & "]" If( CInt( SYSDATA ) >= CInt( numMinAvailable ) ) Then CheckDhcpMinAvailable = True Else CheckDhcpMinAvailable = False End If End Function ' ////////////////////////////////////////////////////////////////////////////// ' // ' // Private Functions ' // NOTE: Private functions are used by the above functions, and will not ' // be called directly by the ActiveXperts Network Monitor Service. ' // Private function names start with a lower case character and will ' // not be listed in the Network Monitor's function browser. ' // ' ////////////////////////////////////////////////////////////////////////////// Function checkDhcpValue( strHost, strOID, BYREF numSysData, BYREF strSysExplanation ) Dim objSnmpManager, objConstants, objSnmpObject, strCommunity checkDhcpValue = False ' Default return value numSysData = 0 ' Not used by this function strSysExplanation = "" ' Set initial value strCommunity = "public" ' Create instance of SNMP object Set objSnmpManager = CreateObject("ActiveXperts.SnmpManager") Set objConstants = CreateObject ( "ActiveXperts.ASConstants" ) ' Initialize SNMP object objSnmpManager.ProtocolVersion = objConstants.asSNMP_VERSION_V2C objSnmpManager.Initialize If( objSnmpManager.LastError <> 0 ) Then strSysExplanation = "Unable to initialize Network Component SNMP object" checkDhcpValue = False Exit Function End If ' Open connection to (remote) SNMP agent objSnmpManager.Open strHost, strCommunity If( objSnmpManager.LastError <> 0 ) Then strSysExplanation = "Unable to connect to agent [" & strHost & "] in [" & strCommunity & "] community. Be sure SNMP agent is running" checkDhcpValue = False Exit Function End If On Error Resume Next Set objSnmpObject = objSnmpManager.Get( strOID ) If( objSnmpManager.LastError <> 0 ) Then strSysExplanation = "Unable to retrieve [" & strOID & "]. . Be sure SNMP agent is running" checkDhcpValue = False Exit Function End If On Error Goto 0 numSysData = objSnmpObject.Value strSysExplanation = "Value read: [" & objSnmpObject.Value & "]" checkDhcpValue = True ' Note: type ID's are described in Network Component manual, and included in Network Component samples. objSnmpManager.Close() objSnmpManager.Shutdown() End Function