pysnmp : getCmd, setCmd, nextCmdsnmp <---> get-request, set-request, get-next-request--->
# pip install pysnmp
from pysnmp.entity.rfc3413.oneliner import cmdgen
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
cmdgen.CommunityData('my-agent', 'public', 0),
cmdgen.UdpTransportTarget(('192.168.1.8', 161)),
'iso.3.6.1.2.1.1.1.0'
)
print varBinds
# apt-get install python-netsnmp
import netsnmp
session = netsnmp.Session(DestHost='192.168.1.8', Version=1 , Community='public')
vars = netsnmp.VarList(netsnmp.Varbind('iso.3.6.1.2.1.1.1.0'))
print(session.get(vars))
References :
pysnmp学习(一) - AncerHaides的专栏 - 博客频道 - CSDN.NET
http://ben.akrin.com/?p=1234
http://stackoverflow.com/questions/8601324/how-to-get-data-form-snmp-with-python
沒有留言:
張貼留言