Traditionally Simple Network Management Protocol (SNMP) polling has been
achieved using the command line. There are some freeware GUI's available such as
Cacti but they require a lot of complex configuration to get working and are
overly complicated for the majority of simple applications. In my PhD research I
just needed to poll a few values from equipment in a legacy data centre via
SNMP, store them on a SQL Server database and visualize them using .NET Chart
controls on a website. The code below shows how the GET method in SNMP is called
using C# code.
private
void buttonGet_Click(object
sender, EventArgs e)
{
//empty listbox
listBoxAPC3.Items.Clear();
string output;
string strVersion =
"1";
string strCommunityString =
"public";
//read host from textbox on screen
string strHost = textBoxHost.Text;
//read OID from textbox on screen
string strOID = textBoxOID.Text;
//default timeout
int iTimeout = 10;
output = LaunchExecutable.Run("snmpget.exe", String.Format(" -v{0} -c {1} {2} {3}", strVersion, strCommunityString, strHost, strOID), iTimeout);
//display results
listBoxAPC3.Items.Add(output);
}
The pivotal idea here is that you need to run snmpget.exe from within the .NET
environment as opposed to from the command line. The LaunchExecutable class
(included in the zip file) has a run method which takes:
-
The name of the executable
-
The command line arguments (SNMP version, SNMP community string, host to poll, OID to poll)
-
The timeout value
As parameters and runs the executable as a
process. This class will work for any executable which you normally run from the
command line but now would prefer to include in one of your C#.NET projects.

mandar bhattPosted Jun 26, 2018, 12:58 AM
Hii how can i find all connected device type using SNMP
Gowtham RajamanickamPosted Apr 26, 2016, 3:12 AM
good article
tech supportPosted Feb 3, 2012, 1:58 AM
i like what you did here i found this very useful
Anil KumarPosted Jul 27, 2011, 4:07 AM
Good One
Sam HobbsPosted Jul 26, 2011, 5:33 PM
Thank you, Mark. For the benefit of those of us familiar with the Process class, the LaunchExecutable class uses the Process class to execute the program and it redirects the standard output.