繁体   English   中英

python 的 SNMP 库失败返回 SNMP 详细信息

[英]SNMP library for python failed return SNMP details

无法使用发布在 ( https://snmplabs.thola.io/pysnmp/quick-start.html ) 的示例获取获取 SNMP 变量详细信息,并收到错误响应。 请建议如何修复错误。 提前致谢

Traceback (most recent call last):
  File "d:/WorkFiles/SNMPTest/SNMP.py", line 6, in <module>
    UdpTransportTarget(('snmpsim.try.thola.io', 161)),
  File "D:\Python37\lib\site-packages\pysnmp\hlapi\transport.py", line 19, in __init__
    self.transportAddr = self._resolveAddr(transportAddr)
  File "D:\Python37\lib\site-packages\pysnmp\hlapi\asyncore\transport.py", line 63, in _resolveAddr
    '@'.join([str(x) for x in transportAddr]), sys.exc_info()[1]))
pysnmp.error.PySnmpError: Bad IPv4/UDP transport address snmpsim.try.thola.io@161: [Errno 11001] getaddrinfo failedcaused by <class 'socket.gaierror'>: [Errno 11001] getaddrinfo failed 

**

  • 用于测试的代码

**

from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
           CommunityData('public', mpModel=0),
           UdpTransportTarget(('snmpsim.try.thola.io', 161)),
           ContextData(),
           ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
)

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:
        print(' = '.join([x.prettyPrint() for x in varBind]))

如此处所述,我的公司正试图接管PySNMP生态系统。

因此,您可以使用demo.pysnmp.com来测试典型的 SNMP 命令/操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM