-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathllddevice.py
74 lines (59 loc) · 2.63 KB
/
llddevice.py
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
#!/usr/bin/python3
# coding=utf-8
"""Low level discovery script для обнаружения камер и накопителей в видеорегистраторах
ПЕРЕДАВАЕМЫЙ ПАРАМЕТР
CAM - камеры подключенные к устройствам
HDD - накопители подключенные к устройствам
NVR - Регистраторы
"""
import re
import requests
import sys
import readinifile as readini
from xml.etree import cElementTree as ET
deviceType = sys.argv[1]
if deviceType == 'HDD':
towwwpage = '/ISAPI/ContentMgmt/Storage/hdd'
rootxmltree = 'hdd'
devicename = 'id'
if deviceType == 'CAM':
towwwpage = '/ISAPI/ContentMgmt/InputProxy/channels/'
rootxmltree = 'InputProxyChannel'
devicename = 'name'
# ToDo (исправить)
if deviceType == 'NVR':
towwwpage = '/ISAPI/ContentMgmt/Storage/hdd'
rootxmltree = 'hdd'
devicename = 'id'
deviceList = readini.getAllNVRdevice()
jsondeviceid = ''
def returnRootDeviceList(deviceList):
r = requests.get('http://' + readini.getip(deviceList[i]) + towwwpage,
auth=(readini.getlogin(deviceList[i]), readini.getpassword(deviceList[i])), stream=True)
xmlstring = re.sub('\\sxmlns="[^"]+"', '', r.text, count=40)
return ET.fromstring(xmlstring)
def returnJSONData(deviceType, device_id, deviceList):
if deviceType == 'HDD':
jsondevicefind = ('{"{#DEVICEID}":"' + device_id + '","{#NVRID}":"' + deviceList[i] + '"')
elif deviceType == 'CAM':
jsondevicefind = ('{"{#DEVICENAME}":"' + device_name + '","{#DEVICEID}":"' + device_id + '","{#NVRID}":"' +
deviceList[i] + '"')
return jsondevicefind + '},'
for i in range(len(deviceList)):
root = returnRootDeviceList(deviceList)
if deviceType == 'NVR':
jsondevicefind = ('{"{#NVRID}":"' + deviceList[i] + '"')
jsondeviceid = jsondevicefind + '},' + jsondeviceid
continue
for deviceid in root.findall(rootxmltree):
device_name = deviceid.find(devicename).text
device_id = deviceid.find('id').text
if deviceType == 'HDD':
jsondevicefind = ('{"{#DEVICEID}":"' + device_id + '","{#NVRID}":"' + deviceList[i] + '"')
elif deviceType == 'CAM':
jsondevicefind = ('{"{#DEVICENAME}":"' + device_name + '","{#DEVICEID}":"' + device_id + '","{#NVRID}":"' + deviceList[i] + '"')
jsondeviceid = jsondevicefind + '},' + jsondeviceid
jsondeviceid = jsondeviceid[0:-1]
print('{"data":[' + jsondeviceid + ']}')
# ToDo (аналоговые камеры живут тут)
# http://192.168.5.196/ISAPI/System/Video/inputs/channels