|
|
@@ -18,6 +18,18 @@ def validate_Group(nGroup: int) -> bool:
|
|
|
else:
|
|
|
return True
|
|
|
|
|
|
+def validate_Grouplist(nGrouplist: list) -> bool:
|
|
|
+ nChNum = len(nGrouplist)
|
|
|
+ if nChNum > 72:
|
|
|
+ print('invalid GroupNum!')
|
|
|
+ return False
|
|
|
+ for item in nGrouplist:
|
|
|
+ nvalue = int(item)
|
|
|
+ if nvalue < 1 or nvalue > 72:
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
+
|
|
|
def get_value(devip:str, soid:str) -> str:
|
|
|
# 实现snmpget
|
|
|
g = getCmd(SnmpEngine(), # 创建SNMP引擎
|
|
|
@@ -93,35 +105,45 @@ def TurnOnOff(sDevIp:str, nSock:int, onoff:bool) -> bool:
|
|
|
|
|
|
|
|
|
#打开或关闭制定分组/端口
|
|
|
-def TurnOnOffGroup(sDevIp:str, nGroup:int, onoff:bool) -> bool:
|
|
|
+def TurnOnOffGroup(sDevIp:str, nGroup:int, nGrouplist:list, onoff:bool) -> bool:
|
|
|
if validate_ip(sDevIp) == False:
|
|
|
print('invalid ip address!')
|
|
|
return False
|
|
|
if validate_Group(nGroup) == False:
|
|
|
print('invalid Group!')
|
|
|
return False
|
|
|
- sOId = '1.3.6.1.4.1.2024.1.3.10.1.4.%d' % (nGroup)
|
|
|
- if onoff == True:
|
|
|
- state = '1'
|
|
|
- else:
|
|
|
- state = '0'
|
|
|
+ if validate_Grouplist(nGrouplist) == False:
|
|
|
+ print('invalid GroupNum!')
|
|
|
+ return False
|
|
|
|
|
|
- return set_value(sDevIp, sOId, state)
|
|
|
+ print(nGrouplist)
|
|
|
+
|
|
|
+ for item in nGrouplist:
|
|
|
+ TurnOnOff(sDevIp,int(item),onoff)
|
|
|
+ return True
|
|
|
|
|
|
|
|
|
-#获取分组状态 0-关闭 1-开启
|
|
|
-def GetStatusGroup(sDevIp:str, nGroup:int) -> int:
|
|
|
+#获取分组状态 0-关闭 1-开启 -1-获取失败
|
|
|
+def GetStatusGroup(sDevIp:str, nGroup:int, nGrouplist:list) -> int:
|
|
|
if validate_ip(sDevIp) == False:
|
|
|
print('invalid ip address!')
|
|
|
- return 0
|
|
|
+ return -1
|
|
|
if validate_Group(nGroup) == False:
|
|
|
print('invalid Group!')
|
|
|
- return 0
|
|
|
- sOId = '1.3.6.1.4.1.2024.1.3.10.1.4.%d' % (nGroup)
|
|
|
- value = get_value(sDevIp, sOId)
|
|
|
- if value is None:
|
|
|
- return 0
|
|
|
- rt_value = int(value)
|
|
|
+ return -1
|
|
|
+ if validate_Grouplist(nGrouplist) == False:
|
|
|
+ print('invalid GroupNum!')
|
|
|
+ return -1
|
|
|
+
|
|
|
+ print(nGrouplist)
|
|
|
+
|
|
|
+ rt_value = 1
|
|
|
+
|
|
|
+ for item in nGrouplist:
|
|
|
+ if GetStatus(sDevIp,int(item)) == 0:
|
|
|
+ rt_value = 0
|
|
|
+ print('Get Group %d Status %d' % (nGroup,rt_value))
|
|
|
+
|
|
|
return rt_value
|
|
|
|
|
|
|
|
|
@@ -209,10 +231,17 @@ def GetSockName(sDevIp:str, nSock:int) -> str:
|
|
|
#获取通道1名称
|
|
|
#GetSockName('192.168.1.132',1)
|
|
|
|
|
|
-#打开分组2的所有通道
|
|
|
-#TurnOnOffGroup('192.168.1.132',2,True)
|
|
|
+#打开分组1的所有通道
|
|
|
+#Group1list = [1, 2, 3]
|
|
|
+#TurnOnOffGroup('192.168.1.132',1,Group1list,False)
|
|
|
+#获取分组1的通道状态
|
|
|
+#GetStatusGroup('192.168.1.132',1,Group1list)
|
|
|
+
|
|
|
|
|
|
+#打开分组2的所有通道
|
|
|
+#Group2list = [4, 5, 6, 7, 8]
|
|
|
+#TurnOnOffGroup('192.168.1.132',2,Group2list,True)
|
|
|
#获取分组2的通道状态
|
|
|
-#GetStatusGroup('192.168.1.132',2)
|
|
|
+#GetStatusGroup('192.168.1.132',2,Group2list)
|
|
|
|
|
|
|