Solved

Accessing MIBs programatically using WMI

Posted on 2004-09-24
9
859 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
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)…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now