如何从snmp响应中获取request-id

时间:2018-03-14 09:43:56

标签: django snmp pysnmp

使用wireshark我可以看到当我运行这个程序(How to get the value of OID in Python using PySnmp)时,请求ID会继续,我可以使用python程序获得请求ID编号,当我运行此程序时我基本上给了社区: public和version v2c,但在get-response中我获得了request-id,这就是获取所需的内容。请帮我解决一下这个问题。这是wireshark中snmp响应的图像。

enter image description here

1 个答案:

答案 0 :(得分:3)

嗯,request-id是SNMP机制非常私密的东西。但如果你愿意,你仍然可以得到它。

使用pysnmp,您可以使用内置挂钩让它回调您的函数并向其传递属于处理请求的SNMP引擎的内部数据。

...

# put this in your script's initialization section

context = {}

def request_observer(snmpEngine, execpoint, variables, context):
    pdu = variables['pdu']
    request_id = pdu['request-id']
    # this is just a way to pass fetched data from the callback out
    context['request-id'] = request_id

snmpEngine.observer.registerObserver(
    request_observer,
    'rfc3412.receiveMessage:request',
     cbCtx=context
)

...

现在,一旦您以正常方式收到SNMP消息,其request-id的{​​{1}}应存储在PDU中。您可以通过这种方式获得有关底层SNMP数据结构的所有内容。

相关问题