SNMP and C#

Here's some code I made to use the Windows SNMP Management API with C# and .Net. This is an ASMX file that exposes web methods to perform SNMP get and set operations on a particular OID.

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.


Ken Shirriff: mail to: Ken dot Shirriff at Sun dot com.
This page: http://www.righto.com/pc/snmp.html
Copyright 2003 Ken Shirriff. Last updated 6/16/2003. Use of this software is subject to the terms of the license agreement.