Skip to main content

No project description provided

Project description

SNMP Library for Python

PyPI PyPI Downloads Python Versions GitHub license

This is a pure-Python, open source and free implementation of v1/v2c/v3 SNMP engine distributed under 2-clause BSD license.

The PySNMP project was initially sponsored by a PSF grant. Thank you!

This version is a fork of Ilya Etingof's project etingof/pysnmp. Ilya sadly passed away on 10-Aug-2022. Announcement here. His work is still of great use to the Python community and he will be missed.

Features

  • Complete SNMPv1/v2c and SNMPv3 support
  • SMI framework for resolving MIB information and implementing SMI Managed Objects
  • Complete SNMP entity implementation
  • USM Extended Security Options support (3DES, 192/256-bit AES encryption)
  • Extensible network transports framework (UDP/IPv4, UDP/IPv6)
  • Asynchronous socket-based IO API support
  • Asyncio integration
  • PySMI integration for dynamic MIB compilation
  • Built-in instrumentation exposing protocol engine operations
  • Python eggs and py2exe friendly
  • 100% Python, works with Python 3.7+
  • 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 configuration
  • Optional SNMP engine discovery
  • Shipped with standard SNMP applications (RC3413)

Download & Install

The PySNMP software is freely available for download from PyPI and GitHub.

Just run:

$ pip install pysnmp-lextudio

To download and install PySNMP along with its dependencies:

Besides the library, command-line SNMP utilities written in pure-Python could be installed via:

$ pip install snmpclitools-lextudio

and used in the very similar manner as conventional Net-SNMP tools:

$ snmpget.py -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 demo.pysnmp.com sysDescr.0
SNMPv2-MIB::sysDescr.0 = STRING: Linux zeus 4.8.6.5-smp #2 SMP Sun Nov 13 14:58:11 CDT 2016 i686

Examples

PySNMP is designed in a layered fashion. Top-level and easiest to use API is known as hlapi. Here's a quick example on how to SNMP GET:

from pysnmp.hlapi import *

iterator = getCmd(SnmpEngine(),
                  CommunityData('public'),
                  UdpTransportTarget(('demo.pysnmp.com', 161)),
                  ContextData(),
                  ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))

errorIndication, errorStatus, errorIndex, varBinds = next(iterator)

if errorIndication:  # SNMP engine errors
    print(errorIndication)
else:
    if errorStatus:  # SNMP agent errors
        print('%s at %s' % (errorStatus.prettyPrint(), varBinds[int(errorIndex)-1] if errorIndex else '?'))
    else:
        for varBind in varBinds:  # SNMP response contents
            print(' = '.join([x.prettyPrint() for x in varBind]))

This is how to send SNMP TRAP:

from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    sendNotification(
        SnmpEngine(OctetString(hexValue='8000000001020304')),
        UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
                    authProtocol=usmHMACSHAAuthProtocol,
                    privProtocol=usmAesCfb128Protocol),
        UdpTransportTarget(('demo.pysnmp.com', 162)),
        ContextData(),
        'trap',
        NotificationType(ObjectIdentity('SNMPv2-MIB', 'authenticationFailure'))
    )
)

if errorIndication:
    print(errorIndication)

We maintain publicly available SNMP Agent and TRAP sink at demo.pysnmp.com. You are welcome to use it while experimenting with whatever SNMP software you deal with.

$ python3 examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py
SNMPv2-MIB::sysDescr.0 = SunOS zeus.pysnmp.com 4.1.3_U1 1 sun4m
$
$ python3 examples//hlapi/asyncore/sync/agent/ntforg/v3-inform.py
SNMPv2-MIB::sysUpTime.0 = 0
SNMPv2-MIB::snmpTrapOID.0 = SNMPv2-MIB::warmStart
SNMPv2-MIB::sysName.0 = system name

Other 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 (including this one) for that purpose.

For more example scripts please refer to examples section at pysnmp web site.

Documentation

Library documentation and examples can be found at the pysnmp project site.

If something does not work as expected, please open an issue at GitHub or post your question on Stack Overflow or try browsing pysnmp mailing list archives.

Bug reports and PRs are appreciated! ;-)

Copyright (c) 2005-2019, Ilya Etingof. Copyright (c) 2022, LeXtudio Inc. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysnmp_lextudio-5.0.26.tar.gz (405.4 kB view details)

Uploaded Source

Built Distribution

pysnmp_lextudio-5.0.26-py3-none-any.whl (289.8 kB view details)

Uploaded Python 3

File details

Details for the file pysnmp_lextudio-5.0.26.tar.gz.

File metadata

  • Download URL: pysnmp_lextudio-5.0.26.tar.gz
  • Upload date:
  • Size: 405.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.7.13 Darwin/22.4.0

File hashes

Hashes for pysnmp_lextudio-5.0.26.tar.gz
Algorithm Hash digest
SHA256 2b6b04747cf4b9d7352439de9ed195be6728e594bddbd468574d9f8637b6b1aa
MD5 1cbea063d954c12ab204e7963b9a0fe9
BLAKE2b-256 f035cb74fbc31e3e0e7eba194a4a6a33783e84c6494624dbaee57b5fdaae7f6e

See more details on using hashes here.

File details

Details for the file pysnmp_lextudio-5.0.26-py3-none-any.whl.

File metadata

  • Download URL: pysnmp_lextudio-5.0.26-py3-none-any.whl
  • Upload date:
  • Size: 289.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.7.13 Darwin/22.4.0

File hashes

Hashes for pysnmp_lextudio-5.0.26-py3-none-any.whl
Algorithm Hash digest
SHA256 ed45b1e8f0954397ec2fc89fd5283d4ace4c267a2e86641374b12cd4fb2dcd89
MD5 a30da49e4526db23ae5164ce1364b2f3
BLAKE2b-256 09eec7c525cf9f7eeb96b8f6269adc209f8953a42f6df7fd792564dce51b2643

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page