Pysnmp
From SNMP
Go to text ā
S
imple N
etwork M
anagement P
rotocol
from pysnmp.hlapi import SnmpEngine, CommunityData, UdpTransportTarget,\
ContextData, ObjectType, ObjectIdentity, getCmd
iterator = getCmd(
SnmpEngine(),
CommunityData('rostring', mpModel=1),
UdpTransportTarget(('192.168.11.201', 161)),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0))
)
errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
if errorIndication:
print(errorIndication)
elif errorStatus:
print('{} at {}'.format(errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
for oid, val in varBinds:
print(f'{oid.prettyPrint()} = {val.prettyPrint()}')