Created
November 3, 2022 03:42
-
-
Save yujiterada/92c801794d2585462927e5958aad76b6 to your computer and use it in GitHub Desktop.
Receive SNMP Trap from Meraki Dashboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
from pysnmp.proto import api | |
from pyasn1.codec.ber import decoder | |
port = 162 | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.bind(("", port)) | |
while 1: | |
data, addr = s.recvfrom(4048) | |
print(addr[0]) | |
version = int(api.decodeMessageVersion(data)) | |
if version in api.protoModules: | |
protocol_module = api.protoModules[version] | |
request_message, whole_message = decoder.decode( | |
data, asn1Spec=protocol_module.Message(), | |
) | |
pdu = protocol_module.apiMessage.getPDU(request_message) | |
var_binds = protocol_module.apiPDU.getVarBinds(pdu) | |
for oid, val in var_binds: | |
print(' %s = %s' % (oid.prettyPrint(), val.prettyPrint())) | |
else: | |
print('Unsupported SNMP version %s' % version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment