Solved

Accessing MIBs programatically using WMI

Posted on 2004-09-24
9
875 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

732 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