0

https://github.com/lextm/sharpsnmplib/blob/master/SharpSnmpLib/IP.cs

System.ArgumentException: bytes must contain 4 or 16 elements
at Lextm.SharpSnmpLib.IP..ctor(Tuple`2 length, Stream stream)
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream)
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream)
at Lextm.SharpSnmpLib.Sequence..ctor(Tuple`2 length, Stream stream)
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream)
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream)
at Lextm.SharpSnmpLib.Sequence..ctor(Tuple`2 length, Stream stream)
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream)
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream)
at Lextm.SharpSnmpLib.ResponsePdu..ctor(Tuple`2 length, Stream stream)
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream)
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Stream stream)
at Lextm.SharpSnmpLib.Sequence..ctor(Tuple`2 length, Stream stream)
at Lextm.SharpSnmpLib.DataFactory.CreateSnmpData(Int32 type, Stream stream)
at Lextm.SharpSnmpLib.Messaging.MessageFactory.ParseMessage(Int32 first, Stream stream,            UserRegistry registry)
at Lextm.SharpSnmpLib.Messaging.MessageFactory.ParseMessages(Byte[] buffer, Int32 index, Int32  length, UserRegistry registry)
at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32   timeout, IPEndPoint receiver, UserRegistry registry, Socket udpSocket)
at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver, Socket udpSocket)
at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver)
at Lextm.SharpSnmpLib.Messaging.Messenger.BulkHasNext(VersionCode version, IPEndPoint endpoint,  OctetString community, Variable seed, Int32 timeout, Int32 maxRepetitions, IList`1& next,  IPrivacyProvider privacy, ISnmpMessage& report)
at Lextm.SharpSnmpLib.Messaging.Messenger.BulkWalk(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, IList`1 list, Int32 timeout, Int32 maxRepetitions, WalkMode mode, IPrivacyProvider privacy, ISnmpMessage report)
at Maprinter.snmpWalk..ctor(String IP, String ID, Int32 timeOut)

我正在使用这个库来从网络打印机中提取一些数据。到目前为止,一切正常,大多数打印机都将我正在寻找的数据返回给我。但是当我收到这个错误时,我没有从打印机收到任何东西,那么是什么导致了这个错误?

Messenger.BulkWalk(VersionCode.V2,
                                   new IPEndPoint(IPAddress.Parse("10.0.0.101"), 161),
                                   new OctetString("public"),
                                   new ObjectIdentifier("1.3.6.1"),
                                   result,
                                   timeOut,
                                   10,
                                   WalkMode.Default,
                                   null,
                                   null);
4

1 回答 1

1

该异常可能是由该设备上的 SNMP 代理发送的空IpAddress正文 (0x40, 0x00) 引起的。这违反了标准,因为结果应该是一个Null主体 (0x05, 0x00)。

IpAddressRFC2578中定义,严格为 4 个字节。这就是#SNMP 检查 4 的原因。检查 16 是针对 IPv6 地址的,尽管它们实际上应该受到自定义约定的支持。

在您的情况下,选项可以是,

  • 修复固件,以便发送正确的正文。
  • 修改#SNMP 代码库(MIT/X11 许可证)并满足您的需要。
于 2014-07-07T11:45:54.223 回答