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()