刚刚接触snmp,不太会使用,主要是怎么使用snmp的set方法,确认过ip是正确的,找不到什么原因和解决办法,求指点
IpAddress agent = new IpAddress("192.168.1.224");
UdpTarget target = new UdpTarget((IPAddress)agent, 161, 5000, 1);
//create set pdu
Pdu set_pdu = new Pdu(PduType.Set);
set_pdu.VbList.Add(new Oid(".1.3.6.1.4.1.11.2.3.9.4.2.1.1.1.2.0"), new Integer32(1));
OctetString community = new OctetString("public");
AgentParameters aparam = new AgentParameters(community);
aparam.Version = SnmpVersion.Ver2;
SnmpV2Packet response;
try
{
response = (SnmpV2Packet)target.Request(set_pdu, aparam);
}
catch(Exception ex)
{
MessageBox.Show(String.Format("Request failed with exception: {0}", ex.Message));
target.Close();
return;
}
if (response == null)
{
Console.WriteLine("error");
}
else
{
if (response.Pdu.ErrorStatus != 0)
{
MessageBox.Show(String.Format("SNMP agent returned ErrorStatus {0} on index {1}",response.Pdu.ErrorStatus, response.Pdu.ErrorIndex));
}
else
{
MessageBox.Show(String.Format("Agent response {0}: {1}",response.Pdu[0].Oid.ToString(), response.Pdu[0].Value.ToString()));
}
}