Ken Shirriff -> Pc -> SNMP and C# |
To use this, download the file Snmp.asmx into C:\\Inetpub\Scripts\Snmp.asmx (or the appropriate directory for your IIS setup). You will need to have the .Net framework 1.1 installed. Then access http://localhost/Scripts/Snmp.asmx (or the appropriate path for your system). You should get a page with SNMPget and SNMPset options. To do a get, enter the IP address of the machine with the SNMP agent (e.g. 127.0.0.1), the community (e.g. "public"), and OID (something like 1.3.6.1.2.1.1.0). If these values are all correct, and there is a SNMP server running at that address, you should get the SNMP response back encapsulated in SOAP.
This code uses the snmpapi.dll and mgmtapi.dll files to do the work, and largely consists of the marshalling and unmarshalling code to use routines in those DLLs from C#.
Note that this code is my first C# program, so there is a good chance that it has problems. This also doesn't implement the full complement of SNMP data types. Consider the code a proof of concept and adapt to your own needs.
Also see the SNMP discussion here.