import requests
import urllib3
import re
import hashlib
import time
import base64
import xlrd
import pickle
ip = 'host ip'
passwd = 'mima'
urllib3.disable_warnings()
sess = requests.session()
print('开始')
a1 = sess.get('https://' + ip + '/cas/login', verify=False)
print('正在获取登陆参数')
pwd1 = hashlib.sha256(passwd.encode('utf-8')).hexdigest()
vcode = re.findall(r'vcode" value=".+"', a1.text)[0][14:-1]
password = hashlib.sha256((pwd1 + vcode).encode('utf-8')).hexdigest()
data = {
'username': 'admin',
'password': password,
'codeId': re.findall(r'codeId" value=".+"', a1.text)[0][15:-1],
'vcode': vcode,
'lt': re.findall(r'value="LT-.+"', a1.text)[0][7:-1],
'execution': 'e1s1',
'serviceIP': ip,
'clientIP': '21.37.11.56',
'clientMAC': '',
'loginType': '1',
'_eventId': 'submit',
'url': '',
'pwdStrength': '3'
}
print('单点登陆')
sess.post('https://' + ip + '/cas/login', data=data, verify=False)
print('完成登陆,进入首页,获取session,\n等待2秒钟,防止VMS反应不过来')
sess.get('https://' + ip + '/cas/eportal/home.action', verify=False)
time.sleep(2)
print('登陆VMS')
sess.get('https://' + ip + '/vms/index!CMSIndex.action', verify=False)
unit = []
def get_unit(indexcode, unit_id):
global unit
url = 'https://' + ip + '/vms/fetchAllControlUnit!getAsyncTree.action?flag=organize&postCode='
a3 = sess.get(url + indexcode + '&searchInput=', data={'node': unit_id}, verify=False)
a4 = a3.json()
for x in a4:
if x['id'][:7] == 'control':
unit.append({
'id': x['id'].split('_')[1],
'text': x['text']
})
get_unit(x['indexCode'], x['id'])
get_unit('0', 'controlUnit_1')
print('组织获取完毕')
print(unit)
get_device_url = 'https://' + ip + '/vms/deviceInfo!fetchDeviceInfoListN.action'
device_info = {}
device_ip = {}
for x in unit:
print('开始获取 ' + x['text'] + ' 内设备,组织ID:' + x['id'])
page_data = {
'start': '0',
'limit': '20',
'unitId': x['id'],
'deviceNameLike': ''
}
a5 = sess.post(get_device_url, data=page_data, verify=False)
a6 = a5.json()
if len(a6['items']) == 0:
pass
else:
print('该组织下共有 ' + str(a6['totalCount']) + ' 个设备,正在获取中')
for z in range(a6['totalPage']):
page_data['start'] = str(20 * z)
a7 = sess.post(get_device_url, data=page_data, verify=False)
a8 = a7.json()['items']
for y in a8:
a9 = 'https://' + ip + '/vms/deviceInfo!findDeviceInfoByDeviceId.action'
a10 = sess.post(a9, data={'deviceId': y['deviceId']}, verify=False).json()
device_info[y['deviceId']] = {
'addType': '1',
'alarmInCount': y['alarmInCount'],
'alarmOutCount': y['alarmOutCount'],
'cameraChanCount': y['cameraChanCount'],
'deviceId': y['deviceId'],
'deviceTypeCode': y['typeCode'],
'endIndexCode': '',
'endNetworkAddr': '',
'ipChanCount': y['ipChanCount'],
'name': y['name'],
'networkAddr': y['networkAddr'],
'networkPort': y['networkPort'],
'netZoneId': '',
'pagServerId': y['pagServerId'],
'preIndexCode': '',
'startIndexCode': '',
'startNetworkAddr': '',
'userName': 'admin',
'userPwd': a10['userPwd'],
'capabilitySet': '0',
'indexCode': a10['indexCode'],
'policeId': a10['policeId'],
'relateUserId': '',
'serialNo': a10['serialNo'],
'talkChanCount': a10['talkChanCount'],
}
device_ip[y['networkAddr']] = y['deviceId']
print('获取完成。')
device_info_file = open('device_info_file.pkl', 'wb')
pickle.dump(device_info, device_info_file)
device_info_file.close()
device_ip_file = open('device_ip_file.pkl', 'wb')
pickle.dump(device_ip, device_ip_file)
device_ip_file.close()
xl = xlrd.open_workbook('camera.xlsx')
xl_ip = xl.sheet_by_index(0)
ipc_ip = xl_ip.col_values(0)[1:]
ipc_new_passwd = xl_ip.col_values(1)[1:]
ipc_dict = {}
ipc_count = len(ipc_ip)
for n in range(ipc_count):
ipc_dict[ipc_ip[n]] = ipc_new_passwd[n]
notify_url = 'https://' + ip + '/vms/deviceInfo!saveModifyDeviceInfoN.action'
def notify_info(ip_addr, new_pwd):
dev_id = device_ip[ip_addr]
post_data = device_info[dev_id]
post_data['userPwd'] = base64.b64encode(new_pwd.encode('utf-8')).decode('utf-8')
a11 = sess.post(notify_url, data=post_data, verify=False)
print(a11.text)
for n in ipc_dict.keys():
notify_info(n, ipc_dict[n])
input('修改完成,按任意键退出:')

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195