目前,我正在使用.NET 4.5开发一个C#控制台应用程序,以设置接入点的一些配置值。此接入点位于我的本地网络中。此外,我使用SnmpSharpNet库来发出SNMP请求。为了发出SNMP请求,我使用了SNMP版本2。
问题是我不能向接入点发出SET请求,它总是以"no- access“(错误代码6)响应。但是我可以做GET请求,没有问题。我还检查了MIB文件,我要更改的变量也具有读写权限。
这是我写的代码。
private static LogFile log;
private static SnmpV2Packet response;
private static UdpTarget target;
static void Main(string[] args)
{
try
{
log = new LogFile(args[0]);
target = new UdpTarget((IPAddress)new IpAddress("<host address>"));
Pdu pdu = new Pdu();
pdu.Type = PduType.Set;
pdu.VbList.Add(new Oid("1.3.6.1.4.1.2356.11.2.88.2.0"), new Integer32(1111));
AgentParameters aparam = new AgentParameters(SnmpVersion.Ver2, new OctetString("public"));
response = (SnmpV2Packet)target.Request(pdu, aparam);
}
catch (Exception ex)
{
log.LogError("Request failed with the exception " + ex, "Main");
target.Close();
return;
}
if (response == null)
{
log.LogError("Error in SNMP request", "Main");
}
else
{
//If an incorrect response
if (response.Pdu.ErrorStatus != 0)
{
log.LogError("SNMP agent returned error status " + response.Pdu.ErrorStatus, "Main");
}
//If a successful response
else
{
log.LogInfo("Value of the " + response.Pdu[0].Oid.ToString() + "changed to " + response.Pdu[0].Value.ToString(), "Main");
}
}
target.Close();
log.CloseLogFile();
}这是与MIB文件中的变量相关的部分
-- {SCALAR} 1.3.6.1.4.1.2356.11.2.88.2
lcsSetupWirelessEpaperPort OBJECT-TYPE
SYNTAX Integer32 (0..65535)
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"-- empty --"
::= { lcsSetupWirelessEpaper 2 }我也试过在命令行上使用Net-SNMP。但结果是一样的。
有没有人能告诉我问题是什么,我在这里遗漏了什么。
谢谢。
发布于 2017-03-16 18:33:39
"no- access“(SNMP错误代码6)也可能表示您正在使用的SNMP社区(我猜它是"public”)没有写访问权限。例如,监控系统应该能够读取(获取)某些值,但不能写入(设置)它们。从安全的角度来看,在这种情况下,最好使用仅具有读取访问权限的SNMP社区。
检查AP的SNMP社区配置,确保其具有写入权限。我建议添加一个具有写访问权限的新社区,而不是将访问权限更改为"public“。
https://stackoverflow.com/questions/42830244
复制相似问题