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;

p1.StartInfo.FileName=cmd;
p1.StartInfo.Arguments=arg;
p1.Start();
StreamReader s1 = p1.StandardOutput;
string s=s1.ReadToEnd();
p1.WaitForExit();
if (s.LastIndexOf(split)>0)
{
string [] parse = Regex.Split(s,split);
rtn=parse[1];
}
return(rtn);
}

which calls the SNMP component with:

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

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

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: