• python netsnmp与pysnmp


    据说,如果论性能,netsnmp更强,而且netsnmp天生支持walk, 但是在安装方式上, pysnmp简单直接,netsnmp需要先安装netsnmp,然后安装相应的python模块,比较麻烦。

    参考 http://www.huilog.com/?p=629, 基本上分为下载, python setup.py build, python setup.py install 两步

    而且pysnmp也可以自己写代码实现walk 

    def walk(host, oid, community):
        for (errorIndication,errorStatus,errorIndex,varBinds) in nextCmd(SnmpEngine(), 
            CommunityData(community),
            UdpTransportTarget((host, 161)),
            ContextData(),
            ObjectType(ObjectIdentity(oid)),
            lexicographicMode=False  # 限制其只在指定范围内walk
            ):
            if errorIndication:
                # print(errorIndication, file=sys.stderr)
                break
            elif errorStatus:
                # print('%s at %s' % (errorStatus.prettyPrint(),
                #                     errorIndex and varBinds[int(errorIndex) - 1][0] or '?'),
                #                     file=sys.stderr)
                break
            else:
                # return varBinds
    
                for varBind in varBinds:
                    yield varBind
                #     print(varBind)
    
    def get(host, oid, snmpCommunity):
        errorIndication, errorStatus, errorIndex, varBinds = next(
            getCmd(SnmpEngine(),
                   CommunityData(snmpCommunity),
                   UdpTransportTarget((host, 161)),
                   ContextData(),
                   ObjectType(ObjectIdentity(oid))
                   )
        )
    
        if errorIndication:
            print(errorIndication)
        elif errorStatus:
            print('%s at %s' % (errorStatus.prettyPrint(),
                                errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
        else:
            for varBind in varBinds:
                yield varBind
  • 相关阅读:
    tree
    gridview XML
    http://jingyan.baidu.com/article/22a299b513f3db9e18376a5e.html
    tree btn
    sss rar jar
    ComponentOne Studio
    http://wpf_sl.cnblogs.com/ WPF/Silverlight深蓝团队
    ddddd
    [牛客每日一题] (前缀和+线性 DP) NC15553 数学考试
    [停更一周,我干了什么] [C++/QT] 一个基于avl树,trie树,哈希散列表的英汉词典
  • 原文地址:https://www.cnblogs.com/yeyong/p/10938775.html
Copyright © 2020-2023  润新知