pysnmp的first look

pysnmp支持很多特性,先从最简单的v1同步方式入手

初看还比较简单、

遗留问题:

如何区分v1和v2c(0代表v1,1代表v2c)

结果的类型处理(python是强类型的,处理起来比perl麻烦许多)

 

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
# GET Command Generator
#同步方式的snmpget

from pysnmp.entity.rfc3413.oneliner import cmdgen
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
	cmdgen.CommunityData('my-agent', 'public', 0),
	cmdgen.UdpTransportTarget(('192.168.6.87', 161)),
	'1.3.6.1.2.1.1.1.0',
	'1.3.6.1.2.1.1.2.0'
)
#none
print(errorIndication)
#0
print(errorStatus)
#[(ObjectName(1.3.6.1.2.1.1.1.0), OctetString(hexValue='436973636f20496e7465726e6574776f726b204f7065726174696e672053797374656d20536f667477617265200d0a494f532028746d2920433236303020536f667477617265202843323630302d54454c434f2d4d292c2056657273696f6e2031322e3328313361292c2052454c4541534520534f4654574152452028666332290d0a546563686e6963616c20537570706f72743a20687474703a2f2f7777772e636973636f2e636f6d2f74656368737570706f72740d0a436f707972696768742028632920313938362d3230303520627920636973636f2053797374656d732c20496e632e0d0a436f6d70696c6564204d6f6e2032352d4170722d303520')), (ObjectName(1.3.6.1.2.1.1.2.0), ObjectIdentifier(1.3.6.1.4.1.9.1.208))]
print(varBinds)
#Cisco Internetwork Operating System SoftwareIOS (tm) C2600 Software (C2600-TELCO-M), Version 12.3(13a), RELEASE SOFTWARE (fc2)Technical Support: http://www.cisco.com/techsupportCopyright (c) 1986-2005 by cisco Systems, Inc.Compiled Mon 25-Apr-05
print str(varBinds[0][1]);
#1.3.6.1.4.1.9.1.208
print str(varBinds[1][1]);



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值