-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallgetusers.py
More file actions
48 lines (37 loc) · 1.32 KB
/
allgetusers.py
File metadata and controls
48 lines (37 loc) · 1.32 KB
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
import requests
from requests.auth import HTTPDigestAuth
import json
username = "admin"
password = "123456"
auth = HTTPDigestAuth(username, password)
url = "http://IP/ISAPI/AccessControl/UserInfo/search?format=json"
all_users = []
position = 0
max_results = 50 # можно ставить 30 или 50, зависит от устройства
while True:
payload = {
"UserInfoSearchCond": {
"searchID": "1",
"searchResultPosition": position,
"maxResults": max_results,
"userType": "normal"
}
}
r = requests.post(url=url, auth=auth, data=json.dumps(payload))
data = r.json()
# Проверяем, есть ли данные
users = data.get("UserInfoSearch", {}).get("UserInfo", [])
if not users:
break
all_users.extend(users)
# Проверяем статус - если MORE, значит есть ещё страницы
status = data.get("UserInfoSearch", {}).get("responseStatusStrg", "")
if status != "MORE":
break
# Смещаем позицию дальше
position += max_results
# Выводим общее количество
print(f"Всего пользователей: {len(all_users)}")
# Можно вывести имена
for u in all_users:
print(u.get("employeeNo"), u.get("name"))