pysnmp 抛出 UnknownCommunityName 错误
pysnmp throwing UnknownCommunityName error
我有一个包含 4 个 SNMP 陷阱数据包的 pcap 文件。当我通过 pysnmp 重放数据包时,它抛出错误
DBG: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2023248>}
我已将 PySNMP 配置为接受社区名称为 'public' 的数据包。
config.addV1System(snmpEngine, 'agent', 'public')
当我在 WireShark 中看到数据包时,它显示社区名称为 public 但通过 PySNMP 调试我发现社区名称是 OctetString(相当于 ASCII 中的 public)。我现在该怎么办?
p.s。 Unix 的 snmptrapd 在给定的 pcap 文件中工作正常。
Pysnmp 版本:4.3.1
Pyasn1 版本:0.1.9
编辑
这是调试模式下的完整堆栈跟踪
2016-01-12_04:45:45.42174 2016-01-12 04:45:45,421 pysnmp: handle_read: transportAddress ('192.168.2.17', 162) -> ('0.0.0.0', 162) incomingMessage (70 octets)
2016-01-12_04:45:45.42179 00000: 30 82 00 42 02 01 00 04 07 70 75 62 6C 69 63 00
2016-01-12_04:45:45.42179 00016: A4 34 06 08 2B 06 01 04 01 90 7A 01 40 04 0A 62
2016-01-12_04:45:45.42180 00032: 21 64 02 01 03 02 01 00 43 04 54 10 5A 06 30 16
2016-01-12_04:45:45.42180 00048: 30 82 00 12 06 0D 2B 06 01 04 01 90 7A 01 02 01
2016-01-12_04:45:45.42181 00064: 01 01 02 02 01 02
2016-01-12_04:45:45.42182 DEBUG: handle_read: transportAddress ('192.168.2.17', 162) -> ('0.0.0.0', 162) incomingMessage (70 octets)
2016-01-12_04:45:45.42182 00000: 30 82 00 42 02 01 00 04 07 70 75 62 6C 69 63 00
2016-01-12_04:45:45.42183 00016: A4 34 06 08 2B 06 01 04 01 90 7A 01 40 04 0A 62
2016-01-12_04:45:45.42183 00032: 21 64 02 01 03 02 01 00 43 04 54 10 5A 06 30 16
2016-01-12_04:45:45.42183 00048: 30 82 00 12 06 0D 2B 06 01 04 01 90 7A 01 02 01
2016-01-12_04:45:45.42184 00064: 01 01 02 02 01 02
2016-01-12_04:45:45.42369 2016-01-12 04:45:45,423 pysnmp: receiveMessage: msgVersion 0, msg decoded
2016-01-12_04:45:45.42381 DEBUG: receiveMessage: msgVersion 0, msg decoded
2016-01-12_04:45:45.42587 2016-01-12 04:45:45,425 pysnmp: prepareDataElements: Message:
2016-01-12_04:45:45.42598 version='version-1'
2016-01-12_04:45:45.42606 community=0x7075626c696300
2016-01-12_04:45:45.42614 data=PDUs:
2016-01-12_04:45:45.42621 trap=TrapPDU:
2016-01-12_04:45:45.42628 enterprise=1.3.6.1.4.1.2170.1
2016-01-12_04:45:45.42636 agent-addr=NetworkAddress:
2016-01-12_04:45:45.42643 internet=10.98.33.100
2016-01-12_04:45:45.42650
2016-01-12_04:45:45.42657 generic-trap='linkUp'
2016-01-12_04:45:45.42664 specific-trap=0
2016-01-12_04:45:45.42673 time-stamp=1410357766
2016-01-12_04:45:45.42683 variable-bindings=VarBindList:
2016-01-12_04:45:45.42685 VarBind:
2016-01-12_04:45:45.42685 name=1.3.6.1.4.1.2170.1.2.1.1.1.2
2016-01-12_04:45:45.42686 value=ObjectSyntax:
2016-01-12_04:45:45.42686 simple=SimpleSyntax:
2016-01-12_04:45:45.42686 number=2
2016-01-12_04:45:45.42687
2016-01-12_04:45:45.42687
2016-01-12_04:45:45.42688
2016-01-12_04:45:45.42688
2016-01-12_04:45:45.42689
2016-01-12_04:45:45.42697
2016-01-12_04:45:45.42697 DEBUG: prepareDataElements: Message:
2016-01-12_04:45:45.42698 version='version-1'
2016-01-12_04:45:45.42698 community=0x7075626c696300
2016-01-12_04:45:45.42699 data=PDUs:
2016-01-12_04:45:45.42699 trap=TrapPDU:
2016-01-12_04:45:45.42699 enterprise=1.3.6.1.4.1.2170.1
2016-01-12_04:45:45.42700 agent-addr=NetworkAddress:
2016-01-12_04:45:45.42700 internet=10.98.33.100
2016-01-12_04:45:45.42701
2016-01-12_04:45:45.42701 generic-trap='linkUp'
2016-01-12_04:45:45.42701 specific-trap=0
2016-01-12_04:45:45.42702 time-stamp=1410357766
2016-01-12_04:45:45.42702 variable-bindings=VarBindList:
2016-01-12_04:45:45.42703 VarBind:
2016-01-12_04:45:45.42703 name=1.3.6.1.4.1.2170.1.2.1.1.1.2
2016-01-12_04:45:45.42710 value=ObjectSyntax:
2016-01-12_04:45:45.42720 simple=SimpleSyntax:
2016-01-12_04:45:45.42720 number=2
2016-01-12_04:45:45.42721
2016-01-12_04:45:45.42721
2016-01-12_04:45:45.42721
2016-01-12_04:45:45.42722
2016-01-12_04:45:45.42722
2016-01-12_04:45:45.42723
2016-01-12_04:45:45.42724 2016-01-12 04:45:45,426 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
2016-01-12_04:45:45.42731 DEBUG: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
2016-01-12_04:45:45.42734 2016-01-12 04:45:45,426 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
2016-01-12_04:45:45.42735 DEBUG: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
只有一个代理存在问题。来自所有其他代理的陷阱被正常处理。
显然,当您从转储的 (?) 数据包构建 PDU 时,您会在 SNMP 社区字符串值中包含尾随零。
>>> from pysnmp.proto.rfc1902 import *
>>> OctetString(hexValue='7075626c696300').asOctets()
'public\x00'
如果这是你想要的,请确保相应地配置 pysnmp。
config.addV1System(snmpEngine, 'agent', 'public\x00')
或
config.addV1System(snmpEngine, 'agent', OctetString(hexValue='7075626c696300'))
我有一个包含 4 个 SNMP 陷阱数据包的 pcap 文件。当我通过 pysnmp 重放数据包时,它抛出错误
DBG: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2023248>}
我已将 PySNMP 配置为接受社区名称为 'public' 的数据包。
config.addV1System(snmpEngine, 'agent', 'public')
当我在 WireShark 中看到数据包时,它显示社区名称为 public 但通过 PySNMP 调试我发现社区名称是 OctetString(相当于 ASCII 中的 public)。我现在该怎么办?
p.s。 Unix 的 snmptrapd 在给定的 pcap 文件中工作正常。
Pysnmp 版本:4.3.1
Pyasn1 版本:0.1.9
编辑 这是调试模式下的完整堆栈跟踪
2016-01-12_04:45:45.42174 2016-01-12 04:45:45,421 pysnmp: handle_read: transportAddress ('192.168.2.17', 162) -> ('0.0.0.0', 162) incomingMessage (70 octets)
2016-01-12_04:45:45.42179 00000: 30 82 00 42 02 01 00 04 07 70 75 62 6C 69 63 00
2016-01-12_04:45:45.42179 00016: A4 34 06 08 2B 06 01 04 01 90 7A 01 40 04 0A 62
2016-01-12_04:45:45.42180 00032: 21 64 02 01 03 02 01 00 43 04 54 10 5A 06 30 16
2016-01-12_04:45:45.42180 00048: 30 82 00 12 06 0D 2B 06 01 04 01 90 7A 01 02 01
2016-01-12_04:45:45.42181 00064: 01 01 02 02 01 02
2016-01-12_04:45:45.42182 DEBUG: handle_read: transportAddress ('192.168.2.17', 162) -> ('0.0.0.0', 162) incomingMessage (70 octets)
2016-01-12_04:45:45.42182 00000: 30 82 00 42 02 01 00 04 07 70 75 62 6C 69 63 00
2016-01-12_04:45:45.42183 00016: A4 34 06 08 2B 06 01 04 01 90 7A 01 40 04 0A 62
2016-01-12_04:45:45.42183 00032: 21 64 02 01 03 02 01 00 43 04 54 10 5A 06 30 16
2016-01-12_04:45:45.42183 00048: 30 82 00 12 06 0D 2B 06 01 04 01 90 7A 01 02 01
2016-01-12_04:45:45.42184 00064: 01 01 02 02 01 02
2016-01-12_04:45:45.42369 2016-01-12 04:45:45,423 pysnmp: receiveMessage: msgVersion 0, msg decoded
2016-01-12_04:45:45.42381 DEBUG: receiveMessage: msgVersion 0, msg decoded
2016-01-12_04:45:45.42587 2016-01-12 04:45:45,425 pysnmp: prepareDataElements: Message:
2016-01-12_04:45:45.42598 version='version-1'
2016-01-12_04:45:45.42606 community=0x7075626c696300
2016-01-12_04:45:45.42614 data=PDUs:
2016-01-12_04:45:45.42621 trap=TrapPDU:
2016-01-12_04:45:45.42628 enterprise=1.3.6.1.4.1.2170.1
2016-01-12_04:45:45.42636 agent-addr=NetworkAddress:
2016-01-12_04:45:45.42643 internet=10.98.33.100
2016-01-12_04:45:45.42650
2016-01-12_04:45:45.42657 generic-trap='linkUp'
2016-01-12_04:45:45.42664 specific-trap=0
2016-01-12_04:45:45.42673 time-stamp=1410357766
2016-01-12_04:45:45.42683 variable-bindings=VarBindList:
2016-01-12_04:45:45.42685 VarBind:
2016-01-12_04:45:45.42685 name=1.3.6.1.4.1.2170.1.2.1.1.1.2
2016-01-12_04:45:45.42686 value=ObjectSyntax:
2016-01-12_04:45:45.42686 simple=SimpleSyntax:
2016-01-12_04:45:45.42686 number=2
2016-01-12_04:45:45.42687
2016-01-12_04:45:45.42687
2016-01-12_04:45:45.42688
2016-01-12_04:45:45.42688
2016-01-12_04:45:45.42689
2016-01-12_04:45:45.42697
2016-01-12_04:45:45.42697 DEBUG: prepareDataElements: Message:
2016-01-12_04:45:45.42698 version='version-1'
2016-01-12_04:45:45.42698 community=0x7075626c696300
2016-01-12_04:45:45.42699 data=PDUs:
2016-01-12_04:45:45.42699 trap=TrapPDU:
2016-01-12_04:45:45.42699 enterprise=1.3.6.1.4.1.2170.1
2016-01-12_04:45:45.42700 agent-addr=NetworkAddress:
2016-01-12_04:45:45.42700 internet=10.98.33.100
2016-01-12_04:45:45.42701
2016-01-12_04:45:45.42701 generic-trap='linkUp'
2016-01-12_04:45:45.42701 specific-trap=0
2016-01-12_04:45:45.42702 time-stamp=1410357766
2016-01-12_04:45:45.42702 variable-bindings=VarBindList:
2016-01-12_04:45:45.42703 VarBind:
2016-01-12_04:45:45.42703 name=1.3.6.1.4.1.2170.1.2.1.1.1.2
2016-01-12_04:45:45.42710 value=ObjectSyntax:
2016-01-12_04:45:45.42720 simple=SimpleSyntax:
2016-01-12_04:45:45.42720 number=2
2016-01-12_04:45:45.42721
2016-01-12_04:45:45.42721
2016-01-12_04:45:45.42721
2016-01-12_04:45:45.42722
2016-01-12_04:45:45.42722
2016-01-12_04:45:45.42723
2016-01-12_04:45:45.42724 2016-01-12 04:45:45,426 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
2016-01-12_04:45:45.42731 DEBUG: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
2016-01-12_04:45:45.42734 2016-01-12 04:45:45,426 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
2016-01-12_04:45:45.42735 DEBUG: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
只有一个代理存在问题。来自所有其他代理的陷阱被正常处理。
显然,当您从转储的 (?) 数据包构建 PDU 时,您会在 SNMP 社区字符串值中包含尾随零。
>>> from pysnmp.proto.rfc1902 import *
>>> OctetString(hexValue='7075626c696300').asOctets()
'public\x00'
如果这是你想要的,请确保相应地配置 pysnmp。
config.addV1System(snmpEngine, 'agent', 'public\x00')
或
config.addV1System(snmpEngine, 'agent', OctetString(hexValue='7075626c696300'))