Refactor: Update build scripts and improve Telnet handling in SSH flasher
This commit is contained in:
BIN
2023-11-03.webp
BIN
2023-11-03.webp
Binary file not shown.
|
Before Width: | Height: | Size: 7.4 KiB |
@@ -22,12 +22,12 @@ call venv\Scripts\activate.bat
|
|||||||
|
|
||||||
REM 3. Cai dependencies + PyInstaller
|
REM 3. Cai dependencies + PyInstaller
|
||||||
echo [2/4] Installing dependencies...
|
echo [2/4] Installing dependencies...
|
||||||
pip install PyQt6 scapy requests pyinstaller --quiet
|
pip install -r requirements.txt pyinstaller --quiet
|
||||||
|
|
||||||
REM 4. Build .exe
|
REM 4. Build .exe
|
||||||
echo [3/4] Building executable...
|
echo [3/4] Building executable...
|
||||||
pyinstaller ^
|
pyinstaller ^
|
||||||
--name "MiraV3_Firmware_Loader" ^
|
--name "Mira_Firmware_Loader_v1.1.0" ^
|
||||||
--icon "icon.ico" ^
|
--icon "icon.ico" ^
|
||||||
--add-data "icon.ico;." ^
|
--add-data "icon.ico;." ^
|
||||||
--onefile ^
|
--onefile ^
|
||||||
@@ -47,11 +47,11 @@ echo.
|
|||||||
echo [4/4] Build complete!
|
echo [4/4] Build complete!
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
if exist "dist\MiraV3_Firmware_Loader.exe" (
|
if exist "dist\Mira_Firmware_Loader_v1.1.0.exe" (
|
||||||
echo ✅ SUCCESS: dist\MiraV3_Firmware_Loader.exe
|
echo SUCCESS: dist\Mira_Firmware_Loader_v1.1.0.exe
|
||||||
echo.
|
echo.
|
||||||
echo File size:
|
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.
|
||||||
echo Ban co the copy file .exe nay sang may khac va chay truc tiep.
|
echo Ban co the copy file .exe nay sang may khac va chay truc tiep.
|
||||||
) else (
|
) else (
|
||||||
|
|||||||
@@ -30,7 +30,40 @@ def _create_ssh_client(ip, user, password, timeout=15):
|
|||||||
time.sleep(1)
|
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",
|
def set_device_password(ip, user="root", old_password="", new_password="admin123a",
|
||||||
status_cb=None):
|
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)
|
# 1. Thử Telnet trước (OpenWrt mặc định mở Telnet 23 và cấm SSH Root khi chưa có Pass)
|
||||||
try:
|
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
|
# Nếu vô được Telnet tức là thiết bị vừa Reset cứng chưa có pass
|
||||||
if status_cb:
|
if status_cb:
|
||||||
status_cb("Telnet connected! Setting password...")
|
status_cb("Telnet connected! Setting password...")
|
||||||
|
|||||||
4
main.py
4
main.py
@@ -47,7 +47,7 @@ class App(QWidget):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.setWindowTitle("MiraV3 Firmware Loader")
|
self.setWindowTitle("Mira Firmware Loader")
|
||||||
self.setWindowIcon(QIcon(resource_path("icon.ico")))
|
self.setWindowIcon(QIcon(resource_path("icon.ico")))
|
||||||
# Data state
|
# Data state
|
||||||
self.local_ip = ""
|
self.local_ip = ""
|
||||||
@@ -67,7 +67,7 @@ class App(QWidget):
|
|||||||
layout.setContentsMargins(8, 6, 8, 6)
|
layout.setContentsMargins(8, 6, 8, 6)
|
||||||
|
|
||||||
# ── Title ──
|
# ── Title ──
|
||||||
title = QLabel("⚡ MiraV3 Firmware Loader")
|
title = QLabel("⚡ Mira Firmware Loader")
|
||||||
title.setObjectName("title")
|
title.setObjectName("title")
|
||||||
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
layout.addWidget(title)
|
layout.addWidget(title)
|
||||||
|
|||||||
11
run.bat
11
run.bat
@@ -3,14 +3,15 @@ REM IoT Firmware Loader - Windows launcher
|
|||||||
|
|
||||||
cd /d "%~dp0"
|
cd /d "%~dp0"
|
||||||
|
|
||||||
if exist "venv" (
|
if not exist "venv" (
|
||||||
call venv\Scripts\activate.bat
|
|
||||||
) else (
|
|
||||||
echo Creating virtual environment...
|
echo Creating virtual environment...
|
||||||
python -m venv venv
|
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...
|
echo Starting IoT Firmware Loader...
|
||||||
python main.py
|
python main.py
|
||||||
|
|||||||
Reference in New Issue
Block a user