?
Solved

Accessing MIBs programatically using WMI

Posted on 2004-09-24
9
Medium Priority
?
895 Views
Last Modified: 2012-06-21
I found this example on technet and it works great.  If i open up the RFC1213 MIB and look around I can change the code to access different OIDs.  The question I have is how does one know what to put in script to access another MIB?  They use the string "SNMP_RFC1213_MIB_ifTable".  What if I want to use a different MIB?

strTargetSnmpDevice = "192.168.0.1"
Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost")
Set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", "public"
Set colIfTable = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_ifTable", , _
                                            objWmiNamedValueSet)
For Each objInterface In colIfTable
    WScript.Echo "ifIndex [Key]:        " & objInterface.ifIndex  & vbCrLf & _
        "   ifAdminStatus:     " & objInterface.ifAdminStatus     & vbCrLf & _
        "   ifDescr:           " & objInterface.ifDescr           & vbCrLf & _
        "   ifInDiscards:      " & objInterface.ifInDiscards      & vbCrLf & _
        "   ifInErrors:        " & objInterface.ifInErrors        & vbCrLf & _
        "   ifInNUcastPkts:    " & objInterface.ifInNUcastPkts    & vbCrLf & _
        "   ifInOctets:        " & objInterface.ifInOctets        & vbCrLf & _
        "   ifInUcastPkts:     " & objInterface.ifInUcastPkts     & vbCrLf & _
        "   ifInUnknownProtos: " & objInterface.ifInUnknownProtos & vbCrLf & _
        "   ifLastChange:      " & objInterface.ifLastChange      & vbCrLf & _
        "   ifMtu:             " & objInterface.ifMtu             & vbCrLf & _
        "   ifOperStatus:      " & objInterface.ifOperStatus      & vbCrLf & _
        "   ifOutDiscards:     " & objInterface.ifOutDiscards     & vbCrLf & _
        "   ifOutErrors:       " & objInterface.ifOutErrors       & vbCrLf & _
        "   ifOutNUcastPkts:   " & objInterface.ifOutNUcastPkts   & vbCrLf & _
        "   ifOutOctets:       " & objInterface.ifOutOctets       & vbCrLf & _
        "   ifOutQLen:         " & objInterface.ifOutQLen         & vbCrLf & _
        "   ifOutUcastPkts:    " & objInterface.ifOutUcastPkts    & vbCrLf & _
        "   ifPhysAddress:     " & objInterface.ifPhysAddress     & vbCrLf & _
        "   ifSpecific:        " & objInterface.ifSpecific        & vbCrLf & _
        "   ifSpeed:           " & objInterface.ifSpeed           & vbCrLf & _
        "   ifType:            " & objInterface.ifType            & vbCrLf
Next
0
Comment
Question by:stealth188
  • 4
  • 4
9 Comments
 
LVL 41

Expert Comment

by:graye
ID: 12150589
I'd suggest that you use the WMI tools from microsoft to browse the SNMP namespaces
http://www.microsoft.com/downloads/details.aspx?FamilyId=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12157069
What is your requirement that makes you ask this question?  What information are you needing to access with WMI?

Bob
0
 
LVL 1

Author Comment

by:stealth188
ID: 12157533
I am trying to access the following OID.  A gentleman was kind enough to tell me where to find the data but now that I am trying to implement it i'm consfused about how to tell WMI what MIB to look at.

http://www.experts-exchange.com/Hardware/Routers/Q_21143208.html
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 1

Author Comment

by:stealth188
ID: 12157721
I can't see where I can pass a community string when I am trying to connect to "root\snmp\localhost".  It just gives me an error saying that WMI is unavailable on that host.  Makes sense because it isn't a Windows device.  I'm sure i'm being dense but can you give me a hint as to how I can connect using the tools?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12159333
Here is the .NET way:

   Public Function SystemDriverList() As ArrayList

      Dim arrayDrivers As ArrayList = New ArrayList

      Try

         Dim searchDrivers As System.Management.ManagementObjectSearcher = _
            New System.Management.ManagementObjectSearcher( _
            "Select * FROM Win32_SystemDriver")

         Dim objectDriver As System.Management.ManagementObject

         For Each objectDriver In searchDrivers.Get()

            arrayDrivers.Add(objectDriver("Name").ToString)

         Next

      Catch ex As Exception

         MessageBox.Show(ex.Message)

      End Try

      Return arrayDrivers

   End Function

We would just need to find the Win32 WMI class that provides you the information that you need.

Bob
0
 
LVL 1

Author Comment

by:stealth188
ID: 12160866
.Net says that system.management.managementobjectsearcher is not a valid namespace.  Do I need to install something in order to access the namespace?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12160901
Yes, you need to add a reference to the System.Management.dll.

Bob
0
 
LVL 1

Author Comment

by:stealth188
ID: 12163697
That seems to return a list of services on my local PC.  How can I convince it to interrogate the router?

Thanks!
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 12163732
I am sorry for the confusion.  I was trying to say that this is only a starting example.  We need to find the right Win32 class and the properties for the device you are querying.  Here is a list of the Win32 classes:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_classes.asp

Bob
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question