tg_monitor_bot/test_ssh.py

37 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import paramiko
import os
from config import HOSTS_LIST
for host in HOSTS_LIST:
print(f"\n🔍 Проверяю {host['name']} ({host['ip']})")
print(f" Пользователь: {host['user']}")
print(f" Ключ: {host['key_path']}")
# Проверяем существование ключа
if not os.path.exists(host['key_path']):
print(f" ❌ Файл ключа НЕ СУЩЕСТВУЕТ: {host['key_path']}")
continue
# Пробуем подключиться
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(
hostname=host['ip'],
port=host['port'],
username=host['user'],
key_filename=host['key_path'],
timeout=5
)
print(" ✅ Подключено успешно!")
# Проверяем тип хоста
stdin, stdout, stderr = client.exec_command("uname -a")
print(f" Система: {stdout.read().decode().strip()}")
client.close()
except paramiko.AuthenticationException:
print(" ❌ Ошибка аутентификации! Неверный логин или ключ")
except Exception as e:
print(f" ❌ Ошибка: {e}")