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);
异常可能是由该设备上发送空IpAddress
主体(0x40,0x00(的SNMP代理引起的。这违反了标准,因为结果应该是Null
主体(0x05,0x00(。
IpAddress
是在RFC2578中定义的,它严格地由4个字节组成。这就是为什么#SNMP检查4。针对16的检查是针对IPv6地址的,尽管它们实际上应该受到自定义约定的支持。
在您的情况下,选项可以是,
- 修复固件,以便发送正确的正文
- 修改#SNMP代码库(MIT/X11许可证(并满足您的需求