Reading an SNMP OID - Code Only Solution

I have to get the value of an SNMP OID in a code only solution. I've managed to open a session, but am struggling to send an OID and return valid data. If anyone can help complete the below function, or suggest a complete code replacement, the points are theirs.

I need a NON-3rd part control/dll/ocx solution. MGMTAPI.dll is allowed because its inherent to Windows NT.


Option Explicit
Private Declare Function SnmpMgrOpen Lib "MGMTAPI" (ByVal pszAgentAddress As Long, ByVal pszCommunityName As Long, ByVal nTimeout As Long, ByVal nRetries As Long) As Long
Private Declare Function SnmpMgrClose Lib "MGMTAPI" (ghMgmtSession As Long) As Long
Private Declare Function SnmpMgrRequest Lib "MGMTAPI" (ByVal ghMgmtSession As Long, ByVal requestType As Long, ByVal SnmpVarBindList As Long, ByVal nErrorStatus As Long, ByVal nErrorIndex As Long) As Long
Public Function GetSNMPData(ByVal strIPAddress As String, ByVal strCommunityString As String, ByVal strOID As String) As String
    Dim lngReturnCode As Long
    Dim lngSession As Long
    lngSession = SnmpMgrOpen(StrPtr(strIPAddress), StrPtr(strCommunityString), 1000, 3)
    If lngSession <> 0 Then

        ' lngReturnCode = SnmpMgrRequest(  << This is where I got stuck >>  )

        Call SnmpMgrClose(lngSession)
    End If
End Function
Sub Main()
    Debug.Print GetSNMPData("", "public", "")
End Sub
Who is Participating?
Computer101Connect With a Mentor Commented:
Placed in PAQ

E-E Moderator
I have a couple of suggestions;

First go to a site like
and get a trial of their software.  Even though you don't want to use it for
your final solution, it will help you to understand the construction and rules of SNMP messages.

Second, if you want an open-source example of an SNMP library you might start here;
you could also go to the Linux code storage website and get a Linux version, which
would also give you good examples.

I haven't used the MS SNMP functions, but there are some examples in the MSDN
library CD's.

A further comment;
You said
I have to get the value of an SNMP OID in a code only solution.

If you only have to get one value from a fixed IP, then you could consider using
a "canned" message.  An SNMP message is such partly because it is sent
in UDP to a certain port.  You can hard code a message in the correct form
(including the BER conversion) and send it out, and if it's up the agent will
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

For example, your debug request is for the "SystemId" which returns a string, ie.     HP ETHERNET MULTI-ENVIRONMENT,ROM A.05.03,JETDIRECT,JD24,EEPROM A.05.05

from a typical HP printer.

You might have to ask for depending on the type of request executed.
LadyVyxenAuthor Commented:
I've trolled through the Dart PowerTCP control, and its too high-level to be useful. I really need a function that does GetSNMPData(IP, Community, OID) that doesn't use 3'rd party. The reason for not using 3rd party is that our process for testing 3rd party products would take far longer than timescales set for this project, and I don't personally have time to dig in-depth into the protocol proper to be able to code at the winsock level.
Then you're probably out of luck.  As far as I know I am the only person
using the E-E website who ever answers questions about SNMP, and I do
not know of a free SNMP library that is easy enough to use without some
understanding of SNMP.  And writing one would be considerably more than
however many points you have.

You may eventually get MGMTAPI to work, but I'm not sure it's happy under
NT (I used to have an NT machine, and thats when I decided to use dart.).
It is built into W2000 I think, but I don't know about WME.

You are welcome to reject this, but even a "you can't do that" is an answer.
LadyVyxenAuthor Commented:
 For 300 points, "You can't do that" is not an acceptable answer when I've gotten about 80% of the code working already and just needed help with a single dll call (SnmpMgrRequest).
  It may be that noone on the list can help, which is fine, and is probably true as noone else has attempted an answer. But I *know* it *can* be done - Ive seen it done elsewhere, and I'm not after 3rd party OCXs, so this question has not been answered and is still an open query.
Hi LadyVyxen,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Refund points and save as a 0-pt PAQ.

EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
DanRollins -- EE database cleanup volunteer
LadyVyxenAuthor Commented:
Actually, Im still waiting for an answer...!
Hi LadyVyxen,
It's a sad fact, but if a question lies dormant for even one month, it will very seldom get an answer.  This question is OVER ONE YEAR OLD!  Time to swab the deck and blow the pipes.  Stick a fork in it Lady, this one is DONE :0)

Your best bet to get an answer is to post a new question and let this one close out (A Moderator will process the refund in seven days).  The Experts keep a hawkeye out for new 300- to 500-point questions, but they never bother to check these old ones.

-- Dan
You might also consider thanking 3rsrichard for the help -- by accepting one of his comments as an answer -- even if it did not answer your question -- there was certainly some significant effort put in there.
-- Dan
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.