我想关闭并且不关闭交换机的端口
I want to shutdown and no shutdown the ports of the Switch
我的交换机是 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'"
确保您使用的是最新的 pyasn1/pysnmp。从回溯看来你是 运行 一些旧的 pyasn1.
我的交换机是 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'"
确保您使用的是最新的 pyasn1/pysnmp。从回溯看来你是 运行 一些旧的 pyasn1.