Package: pysnmp-lextudio
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 3.8+MT-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:$pipinstallpysnmp-lextudioTo download and install PySNMP along with its dependencies:PyASN1PySMI(required for MIB services only)Optionalpysnmpcryptopackage
whenever strong SNMPv3 encryption is desiredBesides the library, command-lineSNMP utilitieswritten in pure-Python could be installed via:$pipinstallsnmpclitools-lextudioand used in the very similar manner as conventional Net-SNMP tools:$snmpget.py-v3-lauthPriv-uusr-md5-des-Aauthkey1-Xprivkey1demo.pysnmp.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:importasynciofrompysnmp.hlapi.asyncio.slimimportSlimfrompysnmp.smi.rfc1902importObjectIdentity,ObjectTypeasyncdefrun():slim=Slim(1)errorIndication,errorStatus,errorIndex,varBinds=awaitslim.get('public','demo.pysnmp.com',161,ObjectType(ObjectIdentity("SNMPv2-MIB","sysDescr",0)),)iferrorIndication:print(errorIndication)eliferrorStatus:print("{}at{}".format(errorStatus.prettyPrint(),errorIndexandvarBinds[int(errorIndex)-1][0]or"?",))else:forvarBindinvarBinds:print(" = ".join([x.prettyPrint()forxinvarBind]))slim.close()asyncio.run(run())This is how to send SNMP TRAP:importasynciofrompysnmp.hlapi.asyncioimport*asyncdefrun():snmpEngine=SnmpEngine()errorIndication,errorStatus,errorIndex,varBinds=awaitsendNotification(snmpEngine,CommunityData('public',mpModel=0),UdpTransportTarget(('demo.pysnmp.com',162)),ContextData(),"trap",NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")).addVarBinds(("1.3.6.1.6.3.1.1.4.3.0","1.3.6.1.4.1.20408.4.1.1.2"),("1.3.6.1.2.1.1.1.0",OctetString("my system")),),)iferrorIndication:print(errorIndication)snmpEngine.transportDispatcher.closeDispatcher()asyncio.run(run())We maintain publicly available SNMP Agent and TRAP sink atdemo.pysnmp.com. You are
welcome to use it while experimenting with whatever SNMP software you deal with.$python3examples/hlapi/asyncio/manager/cmdgen/usm-sha-aes128.py
SNMPv2-MIB::sysDescr.0=SunOSzeus.pysnmp.com4.1.3_U11sun4m
$
$python3examples/hlapi/asyncio/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.
Copyright (c) 2022-2024,LeXtudio Inc.
All rights reserved.