Go to file
Ilya Etingof c54a3f6dc8 WIP: gracefully shutdown asyncio dispatcher 2016-11-05 22:59:31 +01:00
docs switched from PyCrypto to PyCryptodome 2016-11-05 22:34:30 +01:00
examples WIP: gracefully shutdown asyncio dispatcher 2016-11-05 22:59:31 +01:00
pysnmp WIP: gracefully shutdown asyncio dispatcher 2016-11-05 22:59:31 +01:00
.gitignore add .gitignore 2016-03-16 07:59:10 +01:00
.travis.yml Use pip to install local package. 2016-10-31 17:50:18 -04:00
CHANGES.txt switched from PyCrypto to PyCryptodome 2016-11-05 22:34:30 +01:00
LICENSE.txt copyright updated 2015-12-29 20:34:33 +00:00
MANIFEST.in travis added 2016-03-12 10:08:18 +01:00
README.md switched from PyCrypto to PyCryptodome 2016-11-05 22:34:30 +01:00
THANKS.txt cosmetic fixes to 3DES fixes 2016-08-21 18:05:32 +02:00
TODO.txt WIP: gracefully shutdown asyncio dispatcher 2016-11-05 22:59:31 +01:00
requirements.txt switched from PyCrypto to PyCryptodome 2016-11-05 22:34:30 +01:00
runtests.sh pep8 fixes 2016-03-30 23:29:55 +02:00
setup.cfg wheel distribution format now supported 2015-08-17 22:10:27 +00:00
setup.py switched from PyCrypto to PyCryptodome 2016-11-05 22:34:30 +01:00

README.md

SNMP library for Python

Downloads PyPI Python Versions Build status 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!

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 and UNIX domain sockets already implemented)
  • Asynchronous socket-based IO API support
  • Twisted, Asyncio and Trollius integration
  • PySMI integration for dynamic MIB compilation
  • Python eggs and py2exe friendly
  • 100% Python, works with Python 2.4 though 3.5
  • MT-safe (only if run locally to a thread)

Features, specific to SNMPv3 model include:

  • USM authentication (MD5/SHA) and privacy (DES/AES) protocols (RFC3414)
  • 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

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

Installation

Just run:

$ pip install pysnmp

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 pysnmp-apps

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.snmplabs.com sysDescr.0
SNMPv2-MIB::sysDescr.0 = DisplayString: SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m 

Examples

PySNMP is designed highly modular and implements many programming interfaces. Most high-level and easy to use API is called hlapi and can be used like this:

from pysnmp.hlapi import *

iterator = getCmd(SnmpEngine(),
                  CommunityData('public'),
                  UdpTransportTarget(('demo.snmplabs.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]))

or, 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.snmplabs.com', 162)),
        ContextData(),
        'trap',
        NotificationType(ObjectIdentity('SNMPv2-MIB', 'authenticationFailure'))
    )
)

if errorIndication:
    print(errorIndication)

We maintain publicly available SNMP Agent and TRAP sink at demo.snmplabs.com. You are welcome to play with it while experimenting with your PySNMP scripts.

$ python3 examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py
SNMPv2-MIB::sysDescr.0 = SunOS zeus.snmplabs.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 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

Detailed information on SNMP design, history as well as PySNMP programming interfaces could be found at pysnmp site.

Getting help

If something does not work as expected, try browsing PySNMP mailing list archives or post your question to Stack Overflow.

Feedback and collaboration

I'm interested in bug reports, fixes, suggestions and improvements. Your pull requests are very welcome!

Copyright (c) 2005-2016, Ilya Etingof. All rights reserved.