我想关闭并且不关闭Switch的端口

时间:2017-05-17 16:06:21

标签: python linux raspberry-pi3 cisco pysnmp

我的交换机是Catalyst 2960-x系列,我已经配置了SNMP,我现在正在使用PySNMP,但我是新的,我已经知道我必须使用的命令是这个“sudo snmpset -v 2c - c SNMPv2-SMI :: mib-2.105.1.1.1.3.1.13 i 2“。但是我没有完成它,有人可以帮忙。

from pysnmp.hlapi import*
setcommunity = 'EuricoFerreira'
host = '192.168.150.231'
port = 13

snmp_engine = SnmpEngine()

set_gen = setCmd(snmp_engine,
                 CommunityData(setcommunity),
                 UdpTransportTarget((host, 161)),
                 ContextData(),
                 ObjectType(ObjectIdentity('SNMPv2-SMI', 'mib-2', '105.1.1.1.3.1.%d' % port), Integer(2)))

errorIndication, errorStatus, errorIndex, varBinds = next(set_gen)
if errorIndication or errorStatus:
    print('SNMP error: %s' % errorIndication or errorStatus)
else:
    print('SNMP succeeded')

这段代码给了我这个错误:

" Traceback (most recent call last):
  File "<string>", line 878, in writeTest
  File "<string>", line 570, in writeTest
  File "<string>", line 469, in writeTest
  File "<string>", line 766, in getBranch
pysnmp.smi.error.NoSuchInstanceError: NoSuchInstanceError({'idx': 0, 'name': (1, 3, 6, 1, 6, 3, 18, 1, 1, 1, 8, 115, 45, 55, 50, 50, 51, 54, 51, 55, 52, 52)})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Downloads/pysnmp-4.3.2/snmpTest.py", line 17, in <module>
    errorIndication, errorStatus, errorIndex, varBinds = next(set_gen)
  File "/home/pi/Downloads/pysnmp-4.3.2/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 210, in setCmd
    lookupMib=options.get('lookupMib', True)))
  File "/home/pi/Downloads/pysnmp-4.3.2/pysnmp/hlapi/asyncore/cmdgen.py", line 231, in setCmd
    addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
  File "/home/pi/Downloads/pysnmp-4.3.2/pysnmp/hlapi/lcd.py", line 44, in configure
    authData.securityName
  File "/home/pi/Downloads/pysnmp-4.3.2/pysnmp/entity/config.py", line 71, in addV1System
    ((snmpCommunityEntry.name + (8,) + tblIdx, 'destroy'),)
  File "/home/pi/Downloads/pysnmp-4.3.2/pysnmp/smi/instrum.py", line 250, in writeVars
    return self.flipFlopFsm(self.fsmWriteVar, vars, acInfo)
  File "/home/pi/Downloads/pysnmp-4.3.2/pysnmp/smi/instrum.py", line 218, in flipFlopFsm
    rval = f(tuple(name), val, idx, acInfo)
  File "<string>", line 470, in writeTest
  File "<string>", line 1117, in writeTest
  File "<string>", line 1088, in __delegate
  File "<string>", line 886, in writeTest
  File "<string>", line 793, in createTest
  File "<string>", line 699, in createTest
  File "<string>", line 591, in setValue
  File "<string>", line 289, in setValue
AttributeError: 'RowStatus' object has no attribute 'hasValue'"

1 个答案:

答案 0 :(得分:0)

确保您使用的是最新的pyasn1 / pysnmp。从回溯看起来你正在运行一些旧的pyasn1。