【问题标题】:python netsnmp with twistedpython netsnmp 与扭曲
【发布时间】:2015-02-09 22:13:54
【问题描述】:

我正在尝试查找 Python 的 netsnmp 绑定是否可以使用 twisted 进行异步?如果有人有一个例子,那会很有帮助。我的目标是看看我是否可以以异步方式使用 Python 的 netsnmp 绑定来监听陷阱、发送 SNMP 获取请求等。

【问题讨论】:

    标签: python network-programming twisted snmp


    【解决方案1】:

    到目前为止,我发现 zenoss 写的 pynetsnmp 已经过时了。不确定是否有任何更新的库或者twisted 是否带有他们自己的 SNMP 库?

    【讨论】:

      【解决方案2】:

      你检查 pysnmp 了吗?库支持扭曲。 http://pysnmp.sourceforge.net/examples/v3arch/twisted/contents.html

      from twisted.internet import reactor
      from pysnmp.entity import engine, config
      from pysnmp.entity.rfc3413 import cmdrsp, context
      from pysnmp.carrier.twisted.dgram import udp
      
      snmpEngine = engine.SnmpEngine()
      
      config.addTransport(
          snmpEngine,
          udp.domainName,
          udp.UdpTwistedTransport().openServerMode(('127.0.0.1', 161))
      )
      
      config.addV1System(snmpEngine, 'my-read-area', 'public')
      config.addV1System(snmpEngine, 'my-write-area', 'private')
      
      
      config.addVacmUser(snmpEngine, 1, 'my-read-area', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1))
      config.addVacmUser(snmpEngine, 1, 'my-write-area', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
      
      snmpContext = context.SnmpContext(snmpEngine)
      
      cmdrsp.GetCommandResponder(snmpEngine, snmpContext)
      cmdrsp.SetCommandResponder(snmpEngine, snmpContext)
      cmdrsp.NextCommandResponder(snmpEngine, snmpContext)
      
      reactor.run()
      

      【讨论】:

      • 鼓励链接到外部资源,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及为什么存在。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久离线。
      【解决方案3】:

      http://twistedsnmp.sourceforge.net 就是这样的实现。

      【讨论】:

      • 这是绑定 pysnmp,而不是 netsnmp
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 2011-03-19
      相关资源
      最近更新 更多