问题描述
嘿,我是 python 和 pysnmp 的新手,我想打印 oid 的值,我可以用 snmpwalk 做到这一点:
snmpget -v2c -c public 192.168.88.3 .1.3.6.1.2.1.31.1.1.1.10.2 -Oqv
the output:
1190051781
然后我将输出除以 1000000 供人类阅读 1190.05
现在使用 pysnmp:
from pysnmp.hlapi import *
errorIndication,errorStatus,errorIndex,varBinds = next(
getCmd(SnmpEngine(),CommunityData('public'),UdpTransportTarget(('192.168.88.3',161)),ContextData(),ObjectType(ObjectIdentity('.1.3.6.1.2.1.31.1.1.1.10.2')))
)
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]))
输出:
SNMPv2-SMI::mib-2.31.1.1.1.10.2 = 1192146329
如何将输出打印到变量,例如“流量”并将其除以 100000 流量,输出应为:1190.05
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)