Refactor: Update build scripts and improve Telnet handling in SSH flasher

This commit is contained in:
2026-03-08 17:08:38 +07:00
parent ef363ac61d
commit 1c1fbb7f92
5 changed files with 48 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

View File

@@ -22,12 +22,12 @@ call venv\Scripts\activate.bat
REM 3. Cai dependencies + PyInstaller
echo [2/4] Installing dependencies...
pip install PyQt6 scapy requests pyinstaller --quiet
pip install -r requirements.txt pyinstaller --quiet
REM 4. Build .exe
echo [3/4] Building executable...
pyinstaller ^
--name "MiraV3_Firmware_Loader" ^
--name "Mira_Firmware_Loader_v1.1.0" ^
--icon "icon.ico" ^
--add-data "icon.ico;." ^
--onefile ^
@@ -47,11 +47,11 @@ echo.
echo [4/4] Build complete!
echo.
if exist "dist\MiraV3_Firmware_Loader.exe" (
echo SUCCESS: dist\MiraV3_Firmware_Loader.exe
if exist "dist\Mira_Firmware_Loader_v1.1.0.exe" (
echo SUCCESS: dist\Mira_Firmware_Loader_v1.1.0.exe
echo.
echo File size:
for %%A in ("dist\MiraV3_Firmware_Loader.exe") do echo %%~zA bytes
for %%A in ("dist\Mira_Firmware_Loader_v1.1.0.exe") do echo %%~zA bytes
echo.
echo Ban co the copy file .exe nay sang may khac va chay truc tiep.
) else (

View File

@@ -30,7 +30,40 @@ def _create_ssh_client(ip, user, password, timeout=15):
time.sleep(1)
import telnetlib
import socket
class _SimpleTelnet:
"""Minimal Telnet client using raw sockets (replaces telnetlib removed in Python 3.13+)."""
def __init__(self, host, port=23, timeout=10):
self._sock = socket.create_connection((host, port), timeout=timeout)
def read_very_eager(self):
try:
self._sock.setblocking(False)
data = b""
while True:
try:
chunk = self._sock.recv(4096)
if not chunk:
break
data += chunk
except (BlockingIOError, OSError):
break
self._sock.setblocking(True)
return data
except Exception:
return b""
def write(self, data):
self._sock.sendall(data)
def close(self):
try:
self._sock.close()
except Exception:
pass
def set_device_password(ip, user="root", old_password="", new_password="admin123a",
status_cb=None):
@@ -45,7 +78,7 @@ def set_device_password(ip, user="root", old_password="", new_password="admin123
# 1. Thử Telnet trước (OpenWrt mặc định mở Telnet 23 và cấm SSH Root khi chưa có Pass)
try:
tn = telnetlib.Telnet(ip, timeout=5)
tn = _SimpleTelnet(ip, timeout=5)
# Nếu vô được Telnet tức là thiết bị vừa Reset cứng chưa có pass
if status_cb:
status_cb("Telnet connected! Setting password...")

View File

@@ -47,7 +47,7 @@ class App(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("MiraV3 Firmware Loader")
self.setWindowTitle("Mira Firmware Loader")
self.setWindowIcon(QIcon(resource_path("icon.ico")))
# Data state
self.local_ip = ""
@@ -67,7 +67,7 @@ class App(QWidget):
layout.setContentsMargins(8, 6, 8, 6)
# ── Title ──
title = QLabel("⚡ MiraV3 Firmware Loader")
title = QLabel("⚡ Mira Firmware Loader")
title.setObjectName("title")
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(title)

11
run.bat
View File

@@ -3,14 +3,15 @@ REM IoT Firmware Loader - Windows launcher
cd /d "%~dp0"
if exist "venv" (
call venv\Scripts\activate.bat
) else (
if not exist "venv" (
echo Creating virtual environment...
python -m venv venv
call venv\Scripts\activate.bat
pip install PyQt6 scapy requests
)
call venv\Scripts\activate.bat
echo Checking and installing required packages...
pip install -r requirements.txt --quiet
echo Starting IoT Firmware Loader...
python main.py