Previous Tip  |  Next Tip  |  Design Tips   | [Bill's Home]

231. Creating an SNMP client

[Click here to download install file]
Video: [Click here to see a demo of the software]
[Click here to download NETSNMP]

SNMP is one of the most useful protocols around and it is possible to use it for many applications, such as for network diagnostics, fault finding, and optimization. To install an SNMP agent on your computer you can enable it from Settings->Control Panel->Add/Remove Programs->Add/Remove Windows Components, and then:

For SNMP client I've created a simple version of:

For this I created a static method of:

public static string genSNMP(string cmd,string arg,string split)
Process p1 = new Process();
string rtn="Not found";

p1.StartInfo.UseShellExecute = false;
p1.StartInfo.CreateNoWindow = true ;
p1.StartInfo.RedirectStandardInput = true ;
p1.StartInfo.RedirectStandardOutput = true;
p1.StartInfo.RedirectStandardError = true;

StreamReader s1 = p1.StandardOutput;
string s=s1.ReadToEnd();
if (s.LastIndexOf(split)>0)
string [] parse = Regex.Split(s,split);

which calls the SNMP component with:

if (this.txtIPAddress.Text=="") this.txtIPAddress.Text="";

string s1=genSNMP("snmpget","-Os -c public -v 1 "+this.txtIPAddress.Text+" system.sysDescr.0","STRING: ");
s1=genSNMP("snmpget","-Os -c public -v 1 "+this.txtIPAddress.Text+" system.sysObjectID.0","OID: ");
s1=genSNMP("snmpget","-Os -c public -v 1 "+this.txtIPAddress.Text+" system.sysContact.0","STRING: ");
s1=genSNMP("snmpget","-Os -c public -v 1 "+this.txtIPAddress.Text+" system.sysName.0","STRING: ");

When the SNMP agent is started (with Start SNMP (local), and Go! is pressed it gives the SNMP information for the local Window's machine:

and for the Interface table:

and then for another device (a Wireless access point):

Finally I've updated it a little more with: