From 97603a7328c9526d97c5f4100194661d721fcd20 Mon Sep 17 00:00:00 2001 From: smolkik_adm Date: Thu, 3 Sep 2026 02:38:52 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20agents=5Fip.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agents_ip.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 agents_ip.py diff --git a/agents_ip.py b/agents_ip.py new file mode 100644 index 0000000..c773e7f --- /dev/null +++ b/agents_ip.py @@ -0,0 +1,71 @@ +import requests +import urllib3 + +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + +# --- +BASE_URL = "https://nameserver:9877" + + +COOKIE_STRING = "" + + + +def main(): + try: + # Формируем заголовки запроса, притворяясь авторизованным браузером + headers = { + "Cookie": COOKIE_STRING, + "Content-Type": "application/json", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" + } + + + # Делаем прямой запрос к Resource Manager API + print("📊 Сбор информации об агентах через сессию браузера...") + resources_url = f"{BASE_URL}/api/resource_manager/v1/agents" + response = requests.get(resources_url, headers=headers, verify=False) + + # Проверяем успешность + if response.status_code == 401: + print("❌ Ошибка 401: Сессия устарела или Cookie скопированы неверно. Обновите страницу в браузере и скопируйте Cookie заново.") + return + elif response.status_code != 200: + print(f"❌ Сервер вернул ошибку HTTP {response.status_code}") + print(f"Ответ: {response.text}") + return + + data = response.json() + + agents = [] + # Фильтруем агенты по нужным типам + for item in data.get("items", []): + agent_type = item.get("type") + if agent_type in ["agent"]: + agents.append({ + "name": item.get("name"), + "type": agent_type, + "online": item.get("communication", {}).get("online", False), + "os": item.get("details", {}).get("os", {}).get("name", "N/A"), + "ip": ", ".join(item.get("details", {}).get("ipAddresses", ["N/A"])) + }) + + # Выводим результат в терминал PowerShell + print(f"\n✅ Всего найдено агентов/устройств: {len(agents)}\n") + print(f"{'Имя устройства':<40} | {'Тип':<15} | {'Статус':<8} | {'ОС':<30} | {'IP‑адреса'}") + print("-" * 120) + for agent in agents: + status = "Онлайн" if agent["online"] else "Офлайн" + print( + f"{agent['name']:<40} | " + f"{agent['type']:<15} | " + f"{status:<8} | " + f"{agent['os']:<30} | " + f"{agent['ip']}" + ) + + except Exception as e: + print(f"\n❌ Ошибка выполнения скрипта: {e}") + +if __name__ == "__main__": + main()