Load FW bằng SSH, Thêm tính năng update FW (SSH)
This commit is contained in:
67
debug_ssh.py
Normal file
67
debug_ssh.py
Normal file
@@ -0,0 +1,67 @@
|
||||
# python debug_ssh.py 192.168.11.xxx "3.0.6p5.bin" admin123a
|
||||
import sys
|
||||
import logging
|
||||
import paramiko
|
||||
from ssh_flasher import flash_device_ssh
|
||||
|
||||
def main():
|
||||
print("="*50)
|
||||
print("🔧 CÔNG CỤ DEBUG SSH FLASH CHO MIRAV3")
|
||||
print("="*50)
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("\nSử dụng: source venv/bin/activate && python debug_ssh.py <IP_THIET_BI> <DUONG_DAN_FIRMWARE> [MAT_KHAU_SSH] [--update]")
|
||||
print("Ví dụ: python debug_ssh.py 192.168.11.102 ./3.0.6p5.bin admin123a --update")
|
||||
sys.exit(1)
|
||||
|
||||
args = sys.argv[1:]
|
||||
is_update_mode = "--update" in args
|
||||
if is_update_mode:
|
||||
args.remove("--update")
|
||||
|
||||
test_ip = args[0]
|
||||
test_fw = args[1]
|
||||
test_pass = args[2] if len(args) > 2 else "admin123a"
|
||||
|
||||
print(f"\n[+] Thông số đầu vào:")
|
||||
print(f" - IP Thiết bị : {test_ip}")
|
||||
print(f" - Firmware : {test_fw}")
|
||||
print(f" - Pass SSH : {test_pass}")
|
||||
print(f" - Phân luồng : {'UPDATE FW (set_passwd=False)' if is_update_mode else 'NẠP MỚI FW (set_passwd=True)'}\n")
|
||||
|
||||
print("[*] BẬT CHẾ ĐỘ LOG CHI TIẾT CỦA PARAMIKO/SSH...")
|
||||
# Bật log xuất trực tiếp ra màn hình console để dễ nhìn lỗi
|
||||
logging.getLogger("paramiko").setLevel(logging.DEBUG)
|
||||
console_handler = logging.StreamHandler(sys.stdout)
|
||||
console_handler.setFormatter(logging.Formatter('%(asctime)s [SSH_LOG] %(message)s'))
|
||||
logging.getLogger("paramiko").addHandler(console_handler)
|
||||
|
||||
print("\n" + "-"*50)
|
||||
print("BẮT ĐẦU QUÁ TRÌNH THỰC THI...")
|
||||
print("-"*50 + "\n")
|
||||
|
||||
def print_status(msg):
|
||||
print(f"\n---> TRẠNG THÁI APP: {msg}")
|
||||
|
||||
# Gọi hàm flash (có bật tính năng tự đổi passwd về admin123a trước nếu cần)
|
||||
try:
|
||||
result = flash_device_ssh(
|
||||
ip=test_ip,
|
||||
firmware_path=test_fw,
|
||||
password=test_pass,
|
||||
set_passwd=not is_update_mode,
|
||||
status_cb=print_status
|
||||
)
|
||||
|
||||
print("\n" + "="*50)
|
||||
if result == "DONE":
|
||||
print("🟢 KẾT QUẢ: THÀNH CÔNG (DONE)")
|
||||
else:
|
||||
print(f"🔴 KẾT QUẢ: THẤT BẠI - {result}")
|
||||
print("="*50)
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n🔴 ERROR UNHANDLED EXCEPTION: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user