Package: pysnmplib
SNMP library for PythonThis is a pure-Python, open source and free implementation of v1/v2c/v3
SNMP engine distributed under 2-clauseBSD license.The PySNMP project was initially sponsored by aPSFgrant.
Thank you!This version is a fork of Ilya Etingof's projectetingof/pysnmp. Ilya sadly passed away on 10-Aug-2022. Announcementhere.  His work is still of great use to the Python community and he will be missed.FeaturesComplete SNMPv1/v2c and SNMPv3 supportSMI framework for resolving MIB information and implementing SMI
Managed ObjectsComplete SNMP entity implementationUSM Extended Security Options support (3DES, 192/256-bit AES encryption)Extensible network transports framework (UDP/IPv4, UDP/IPv6)Asynchronous socket-based IO API supportAsynciointegrationPySMIintegration for dynamic MIB compilationBuilt-in instrumentation exposing protocol engine operationsPython eggs and py2exe friendly100% Python, works with Python 2.4 though 3.7MT-safe (if SnmpEngine is thread-local)Features, specific to SNMPv3 model include:USM authentication (MD5/SHA-1/SHA-2) and privacy (DES/AES) protocols (RFC3414, RFC7860)View-based access control to use with any SNMP model (RFC3415)Built-in SNMP proxy PDU converter for building multi-lingual
SNMP entities (RFC2576)Remote SNMP engine configurationOptional SNMP engine discoveryShipped with standard SNMP applications (RC3413)Download & InstallThe PySNMP software is freely available for download fromPyPIandGitHub.Just run:$pipinstallpysnmplibTo download and install PySNMP along with its dependencies:PyASN1PyCryptodomex(required only if SNMPv3 encryption is in use)PySMI(required for MIB services only)Besides the library, command-lineSNMP utilitieswritten in pure-Python could be installed via:$pipinstallsnmpclitoolsand used in the very similar manner as conventional Net-SNMP tools:$snmpget.py-v3-lauthPriv-uusr-md5-des-Aauthkey1-Xprivkey1demo.snmplabs.comsysDescr.0
SNMPv2-MIB::sysDescr.0=STRING:Linuxzeus4.8.6.5-smp#2 SMP Sun Nov 13 14:58:11 CDT 2016 i686ExamplesPySNMP is designed in a layered fashion. Top-level and easiest to use API is known ashlapi. Here's a quick example on how to SNMP GET:frompysnmp.hlapiimport*iterator=getCmd(SnmpEngine(),CommunityData('public'),UdpTransportTarget(('demo.snmplabs.com',161)),ContextData(),ObjectType(ObjectIdentity('SNMPv2-MIB','sysDescr',0)))errorIndication,errorStatus,errorIndex,varBinds=next(iterator)iferrorIndication:# SNMP engine errorsprint(errorIndication)else:iferrorStatus:# SNMP agent errorsprint('%sat%s'%(errorStatus.prettyPrint(),varBinds[int(errorIndex)-1]iferrorIndexelse'?'))else:forvarBindinvarBinds:# SNMP response contentsprint(' = '.join([x.prettyPrint()forxinvarBind]))This is how to send SNMP TRAP:frompysnmp.hlapiimport*errorIndication,errorStatus,errorIndex,varBinds=next(sendNotification(SnmpEngine(OctetString(hexValue='8000000001020304')),UsmUserData('usr-sha-aes128','authkey1','privkey1',authProtocol=usmHMACSHAAuthProtocol,privProtocol=usmAesCfb128Protocol),UdpTransportTarget(('demo.snmplabs.com',162)),ContextData(),'trap',NotificationType(ObjectIdentity('SNMPv2-MIB','authenticationFailure'))))iferrorIndication:print(errorIndication)We maintain publicly available SNMP Agent and TRAP sink atdemo.snmplabs.com. You are
welcome to use it while experimenting with whatever SNMP software you deal with.:warning:This is no longer the case as the snmplabs.com site is now defunct$python3examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py
SNMPv2-MIB::sysDescr.0=SunOSzeus.snmplabs.com4.1.3_U11sun4m
$
$python3examples//hlapi/asyncore/sync/agent/ntforg/v3-inform.py
SNMPv2-MIB::sysUpTime.0=0SNMPv2-MIB::snmpTrapOID.0=SNMPv2-MIB::warmStart
SNMPv2-MIB::sysName.0=systemnameOther than that, PySNMP is capable to automatically fetch and use required MIBs from HTTP, FTP sites
or local directories. You could configure any MIB source available to you (includingthis one) for that purpose.For more example scripts please refer toexamples sectionat pysnmp web site.DocumentationLibrary documentation and examples can be found at thepysnmp project site.If something does not work as expected, pleaseopen an issueat GitHub or
post your questionon Stack Overflowor try browsing pysnmpmailing list archives.Bug reports and PRs are appreciated! ;-)Copyright (c) 2005-2019,Ilya Etingof. All rights reserved.