Reputation: 25
I build a small SNMP v3 trap receiver in python with pysnmp. In our network, the snmp enigine id and the users/passwords are equal on different machines. So i need the snmp trap senders ip address to identify the sending machine. How can i get the address, is there any function/method in pysnmp?
Upvotes: 0
Views: 1293
Reputation: 5555
I think it is generally discouraged in SNMP to rely on peer address because of potential proxy/NAT/etc in-between. That probably explains why peer address information is not exposed in abstract SNMP APIs.
Do get hold of peer address in pysnmp you could use the observer
feature:
# Callback function for receiving notifications
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
varBinds, cbCtx):
execContext = snmpEngine.observer.getExecutionContext(
'rfc3412.receiveMessage:request'
)
print('Notification from %s:%s' % execContext['transportAddress'])
Here is the complete example.
Upvotes: 1