Quicklinks
ActiveSocket provides an easy-to-use development interface to a variety of IP protocols. By using ActiveSocket, you can very easily create or enhance applications with network features.
ActiveSocket features the following: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.
SNMP MIB Browsing can be well integrated into Powershell environments. This document describes how ActiveSocket's SNMP MIB Browser can be integrated into Powershell projects.
A management information base (MIB) is a database used to manage the devices in a communications network. The database is hierarchical (tree-structured) and entries are addressed through object identifiers (OID's). A MIB should contain information on these commands and on the target objects (controllable entities or potential sources of status information) with a view to tuning the network transport to the current needs. Each type of object in a MIB database has a name, a syntax, and an encoding. The name is represented uniquely as an OID. An OID is an administratively assigned name. The administrative policies used for assigning names are discussed later in this memo.
Use ActiveSocket's 'SnmpMibBrowser' object to load a MIB database into memory and iterate over all objects and view all properties.
Download ActiveSocket from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Create a new script using your favorite editor. You can simply use notepad. However, a Powershell editor is recommended, so you can browse through objects, objects properties and object functions.
You're now able to write a more advanced script to communicate using the ActiveSocket Toolkit.
Create a new Powershell file called DEMO.PS1.
Create the ActiveSocket object(s) like this:
$objSnmpMib = new-object -comobject ActiveXperts.SnmpMibBrowser
Now, add the following lines to the file to have your fist ActiveSocket Powershell program:
Write-Host "ActiveSocket Version " $objSnmpMib.Version "; Build " $objSnmpMib.Build "; Module " $objSnmpMib.Module Write-Host "Expiration date: " $objSnmpMib.ExpirationDate
################################################################################# # ActiveSocket - Powershell script # © Copyright ActiveXperts Software B.V. # # For more information about ActiveSocket, please # visit the online ActiveSocket page at: # http://www.activexperts.com ################################################################################# # ActiveSocket sample - SNMP MIB Browser # Load a MIB file, and show all properties ################################################################################# cls ################################################################################# # Functions --------------------------------------------------------------------# ################################################################################# ################################################################################# # ReadInput --------------------------------------------------------------------# function ReadInput($strTitle, $strDefault, $bAllowEmpty) { $strReturn = "" do { $strInput = Read-host $strTitle, "(", $strDefault , ")" if($strInput -ne "") { $strReturn = $strInput } if($bAllowEmpty -eq 1) { break } } while($strReturn -eq "") return $strReturn } ################################################################################# # ShowMIBTree ------------------------------------------------------------------# function ShowMIBTree( $objSnmpMIB, $objConstants, $bVerbose ) { # Start with "iso" $objSnmp = $objSnmpMIB.Get("iso") while ($objSnmpMIB.LastError -eq 0) { Write-Host $objSnmp.Path if( $bVerbose -eq $true ) { $strDescription = Replace( $objSnmp.Description, " [nl] ") $strDescription = Replace( $strDescription, " [nl] ") $nDescription = Len( $strDescription ) if ($nDescription -gt 40) { $strDescription = $strDescription.SubString(0, 40 ) $strDescription = $strDescription + "..." } if ($objSnmp.Access -eq $objConstants.asMIB_ACCESS_NOACCESS) { $strAccess = "NOACCESS" } elseif ($objSnmp.Access -eq $objConstants.asMIB_ACCESS_NOTIFY) { $strAccess = "NOTIFY" } elseif ($objSnmp.Access -eq $objConstants.asMIB_ACCESS_READONLY) { $strAccess = "READONLY" } elseif ($objSnmp.Access -eq $objConstants.asMIB_ACCESS_WRITEONLY) { $strAccess = "WRITEONLY" } elseif ($objSnmp.Access -eq $objConstants.asMIB_ACCESS_READWRITE) { $strAccess = "READWRITE" } elseif ($objSnmp.Access -eq $objConstants.asMIB_ACCESS_READCREATE) { $strAccess = "READCREATE" } else { $strAccess = "n/a" } } if (objSnmp.Status = $objConstants.asMIB_STATUS_CURRENT) { $strStatus -eq "CURRENT" } elseif (objSnmp.Status -eq $objConstants.asMIB_STATUS_DEPRECATED) { strStatus -eq "DEPRECATED" } elseif (objSnmp.Status -eq $objConstants.asMIB_STATUS_OBSOLETE) { strStatus -eq "OBSOLETE" } elseif (objSnmp.Status -eq $objConstants.asMIB_STATUS_MANDATORY) { strStatus -eq "MANDATORY" } else { $strStatus -eq "n/a" } Write-Host " OID: " $objSnmp.OID Write-Host " Description: " $strDescription Write-Host " Syntax: " $objSnmp.Syntax Write-Host " Access: " $strAccess Write-Host " Status: " $strStatus } $objSnmp = $objSnmpMIB.GetNext() } ################################################################################# # THE SCRIPT ITSELF ------------------------------------------------------------# ################################################################################# $objSnmpMib = new-object -comobject ActiveXperts.SnmpMibBrowser $objConstants = new-object -comobject ActiveXperts.ASConstants # Write some information to console Write-Host "ActiveSocket Version " $objSnmpMib.Version "; Build " $objSnmpMib.Build "; Module " $objSnmpMib.Module Write-Host "Expiration date: " $objSnmpMib.ExpirationDate $strMibFile = ReadInput "Enter MIB file (leave blank for a Windows System MIB file)" "c:\windows\system32\mib_ii.mib" 0 if (ReadInput "Verbose output (y/n) ?" "y" 0 = "y") { $bVerbose = $true } else { $bVerbose = $false } Write-Host "MIB File: " $strMibFile # $objSnmpMib.LogFile = "C:\SnmpMib.txt" $objSnmpMib.LoadMibFile($strMibFile) Write-Host "LoadMibFile, result: " $objSnmpMib.LastError " (" $objSnmpMib.GetErrorDescription( $objSnmpMib.LastError ) ")" if( $objSnmpMib.LastError -eq 0 ) { ShowMIBTree($objSnmpMib, $objConstants, $bVerbose) } Write-Host "Ready."
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/network-component.