散尽浮华 2023

過去心不可得,現在心不可得,未來心不可得。
安寻安放,不卑不亢;重剑无锋,大巧不工!
  1. 首页
  2. network
  3. 正文

Python:网络交换机SNMP

2019年1月13日 3431点热度 1人点赞 0条评论

示例(一)

# more snmp1.py 
#!/usr/bin/python3.4
# -*- coding=utf-8 -*-

from pysnmp.hlapi import *

#varBinds是列表,列表中的每个元素的类型是ObjectType(该类型的对象表示MIB variable)
errorIndication, errorStatus, errorindex, varBinds = next(
    getCmd(SnmpEngine(),
          CommunityData('CommunityString'),
          UdpTransportTarget(('交换机IP地址',161)),
          ContextData(),
          ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')),
          ObjectType(ObjectIdentity('1.3.6.1.2.1.1.2.0')))
)

if errorIndication:
    print(errorIndication)
elif errorStatus:
    print('%s at %s' % (
            errorStatus.prettyPrint(),
            errorindex and varBinds[int(errorindex)-1][0] or '?'
        )
    )

for varBind in varBinds:
    print(varBind)

执行结果:

# python snmp1.py 
SNMPv2-MIB::sysDescr.0 = Dell Networking OS
Operating System Version: 2.0
Application Software Version: 9.11(2.1)
Series: S4048T-ON
Copyright (c) 1999-2017 by Dell Inc. All Rights Reserved.
Build Time: Mon Jun  5 09:25:23 2017
SNMPv2-MIB::sysObjectID.0 = SNMPv2-SMI::enterprises.6027.1.3.30
标签: 暂无
最后更新:2019年1月13日

admin

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2023 散尽浮华 2023. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang