1 Star 0 Fork 1

布田智能科技 / pysnmp

forked from Gitee 极速下载 / pysnmp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-2-Clause

SNMP library for Python

PyPI Python Versions GitHub license Build status Downloads

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)
  • Asynchronous socket-based IO API support
  • Twisted, Asyncio and Trollius integration
  • PySMI integration for dynamic MIB compilation
  • Built-in instrumentation exposing protocol engine operations
  • Python eggs and py2exe friendly
  • 100% Python, works with Python 2.6 though 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

to download and install PySNMP along with its dependencies:

  • PyASN1
  • PySMI (required for MIB services only)
  • Optional pysnmpcrypto package whenever strong SNMPv3 encryption is desired

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

$ pip install snmpclitools

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 = 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.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]))

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=USM_AUTH_HMAC96_SHA,
                    privProtocol=USM_PRIV_CFB128_AES),
        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 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.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 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. All rights reserved.

Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
BSD-2-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/btsmart/pysnmp.git
git@gitee.com:btsmart/pysnmp.git
btsmart
pysnmp
pysnmp
master

搜索帮助