我尝试查询Cisco SMB (小型企业交换机)以读取其主机名。
我的代码返回"not in time window (1.3.6.1.6.3.15.1.1.2.0)“。
Net-Snmp工作正常。我发现使用wireshark的不同之处在于net-snmp在收到not in time window错误后设置了msgAuthorativeEngineTime。
Discovery discovery = Messenger.GetNextDiscovery(SnmpType.GetRequestPdu);
ReportMessage report = discovery.GetResponse(60000, new IPEndPoint(IPAddress.Parse("10.105.9.10"), 161));
OctetString username = new OctetString("test");
var auth = new SHA1AuthenticationProvider(new OctetString("Testtest123!"));
var priv = new DESPrivacyProvider(new OctetString("Testtest123!"), auth);
// read switch hostname
GetRequestMessage request = new GetRequestMessage(VersionCode.V3, Messenger.NextMessageId, Messenger.NextRequestId, username, new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.5.0")) }, priv, Messenger.MaxMessageSize, report);
ISnmpMessage reply = request.GetResponse(60000, router); (not in time window)请找到sharp-snmp的wireshark屏幕截图:

和net-snmp:

谢谢你的帮助!
发布于 2021-03-09 23:44:54
根据snmpget示例(更新后的链接here),您必须调用两次GetRequestMessage方法。请注意,代码在第一个调用中使用report变量,然后在后一个调用中使用reply变量,否则它将无法工作(=不在时间窗口消息中)(我花了半天时间才得到这个!)
https://stackoverflow.com/questions/46033360
复制相似问题