我正在使用PySNMP库在Python中尝试从SNMP端口读取数据。 我只对通过此库获取数据感兴趣。 这是因为我正在从NetSNMP转移到PySNMP。
这是我用NetSNMP的工作代码,可以从端口获取数据:
import netsnmp as snmp
infoSet = snmp.Varbind('1.3.6.1.2.1.123.1.7.1.1.0')
infoGet = snmp.snmpget(infoSet, Version = 1, DestHost = 'localhost', Community = "public")
print infoGet
这3行代码可以返回我从该端口获取的实际读数,我正在尝试从PySNMP获取相同的数据,以下是目前的代码。
from pysnmp.entity.rfc3413.oneliner import cmdgen
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
cmdgen.CommunityData('my-agent', 'public', 0),
cmdgen.UdpTransportTarget(('localhost', 161)),
(1,3,6,1,2,1,1,1,0)
)
print varBinds[0][0]
这段代码打印了SNMP地址,我想获取上述端口的实际读数,但是不知道如何实现。我发现很难理解文档。
如果有帮助,将不胜感激。
谢谢