Using wireshark i can see a request-id goes on when i run this program (How to get the value of OID in Python using PySnmp), can i get the request-id number using python program similarly, when i run this program i basically give community:public and version v2c, but in get-response i get request-id, this is what is need to fetch. Please help me out how to do it. Here is the image of snmp response in wireshark.
Asked
Active
Viewed 1,693 times
2
-
1So, did you get your answer? – Lightness Races in Orbit Jan 12 '19 at 22:58
1 Answers
3
Well, request-id
is something very private to the SNMP mechanics. But you still can get it if you want.
With pysnmp, you can use the built-in hooks to have it calling back your function and passing it the internal data belonging to SNMP engine processing the request.
...
# 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
)
...
Now, once you get SNMP message the normal way, request-id
for its PDU
should be stored in context['request-id']
. You can get practically everything about underlying SNMP data structures that way.

Ilya Etingof
- 5,440
- 1
- 17
- 21
-
Excellent answer, one comment: if one is interested in the `request-id` of the SNMP SET executed by pysnmp the `rfc3412.receiveMessage:response` should be "observed". This way the `reuqest-id` can be acquired from the SET RESPONSE message. Based on the screenshot the OP wants the same, get the `request-id` from the response PDU. – Bence Kaulics Jan 11 '19 at 17:42