This commit is contained in:
Local User 2025-12-08 11:27:01 +08:00
parent 4f657c2442
commit 6020b4a908
12 changed files with 12662 additions and 3 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -66,10 +66,10 @@ include CMakeFiles/MacModifier_autogen_timestamp_deps.dir/compiler_depend.make
# Include the progress variables for this target.
include CMakeFiles/MacModifier_autogen_timestamp_deps.dir/progress.make
CMakeFiles/MacModifier_autogen_timestamp_deps: /usr/lib/qt6/libexec/moc
CMakeFiles/MacModifier_autogen_timestamp_deps: /usr/lib/x86_64-linux-gnu/libQt6Widgets.so.6.4.2
CMakeFiles/MacModifier_autogen_timestamp_deps: /usr/lib/qt6/libexec/uic
CMakeFiles/MacModifier_autogen_timestamp_deps: /usr/lib/x86_64-linux-gnu/libQt6Core.so.6.4.2
CMakeFiles/MacModifier_autogen_timestamp_deps: /usr/lib/qt6/libexec/moc
CMakeFiles/MacModifier_autogen_timestamp_deps: /usr/lib/x86_64-linux-gnu/libQt6Widgets.so.6.4.2
MacModifier_autogen_timestamp_deps: CMakeFiles/MacModifier_autogen_timestamp_deps
MacModifier_autogen_timestamp_deps: CMakeFiles/MacModifier_autogen_timestamp_deps.dir/build.make

Binary file not shown.

View File

@ -126,3 +126,399 @@ hwaddress ether 90:A9:F7:30:00:10
OK
2025-11-17 10:48:38 - 已刷新远程MAC: 90:A9:F7:30:00:10
2025-11-19 11:19:47 - 已连接并读取远程MAC: 90:A9:F7:F0:69:FA
2025-11-19 11:19:50 - 远程修改完成
2025-11-19 11:19:50 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:69:FA
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-19 11:19:50 - 远程sync执行失败: kex_exchange_identification: read: Connection reset by peer
2025-11-19 11:20:12 - 远程重启失败: Connection to 10.10.12.12 closed by remote host.
2025-11-19 11:20:21 - 已刷新远程MAC: 90:A9:F7:30:00:00
2025-11-19 11:26:34 - 已连接并读取远程MAC: 90:A9:F7:F0:69:ED
2025-11-19 11:26:36 - 远程修改完成
2025-11-19 11:26:36 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:69:ED
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-19 11:26:36 - 远程sync执行!
2025-11-19 11:26:43 - 远程重启!
2025-11-19 11:27:01 - 刷新失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: Connection timed out
2025-11-19 13:13:42 - 已连接并读取远程MAC: 90:A9:F7:F0:6A:61
2025-11-19 13:13:54 - 远程修改完成
2025-11-19 13:13:54 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:6A:61
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-19 13:13:54 - 远程sync执行!
2025-11-19 13:13:57 - 远程重启!
2025-11-19 13:14:16 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-19 13:16:34 - 刷新失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: Connection timed out
2025-11-19 14:43:19 - 已连接并读取远程MAC: 90:A9:F7:F0:6A:60
2025-11-19 14:43:24 - 远程修改完成
2025-11-19 14:43:24 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:6A:60
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-19 14:43:24 - 远程sync执行!
2025-11-19 14:43:27 - 远程重启!
2025-11-19 14:43:28 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-19 14:55:41 - 已连接并读取远程MAC: 90:A9:F7:F0:69:D5
2025-11-19 14:55:42 - 连接失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-19 14:55:43 - 已连接并读取远程MAC: 90:A9:F7:F0:69:D5
2025-11-19 14:55:51 - 远程修改完成
2025-11-19 14:55:51 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:69:D5
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-19 14:55:51 - 远程sync执行!
2025-11-19 14:55:55 - 远程重启!
2025-11-19 14:55:57 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-19 16:58:31 - 已连接并读取远程MAC: 90:A9:F7:F0:6A:54
2025-11-19 16:58:33 - 远程修改完成
2025-11-19 16:58:33 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:6A:54
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-19 16:58:33 - 远程sync执行!
2025-11-19 16:58:34 - 远程重启!
2025-11-19 17:00:56 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-19 17:05:53 - 连接失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: Connection timed out
2025-11-19 17:05:55 - 已连接并读取远程MAC: 90:A9:F7:F0:6A:53
2025-11-19 17:05:56 - 远程修改完成
2025-11-19 17:05:56 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:6A:53
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-19 17:05:56 - 远程sync执行!
2025-11-19 17:05:58 - 远程重启!
2025-11-19 17:06:02 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-19 17:33:04 - 连接失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: Connection timed out
2025-11-19 17:33:06 - 已连接并读取远程MAC: 90:A9:F7:F0:6A:55
2025-11-19 17:33:10 - 远程修改完成
2025-11-19 17:33:10 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:6A:55
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-19 17:33:10 - 远程sync执行!
2025-11-19 17:33:14 - 远程重启!
2025-11-19 17:33:15 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-19 17:35:31 - 连接失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: Connection timed out
2025-11-19 17:35:32 - 已连接并读取远程MAC: 90:A9:F7:F0:6A:56
2025-11-19 18:18:56 - 刷新失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: Connection timed out
2025-11-19 18:18:58 - 已连接并读取远程MAC: 90:A9:F7:F0:69:D5
2025-11-19 18:19:01 - 远程修改完成
2025-11-19 18:19:01 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:69:D5
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-19 18:19:01 - 远程sync执行!
2025-11-19 18:19:02 - 远程重启!
2025-11-20 12:33:42 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-20 12:36:18 - 连接失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: Connection timed out
2025-11-20 12:36:20 - 已连接并读取远程MAC: 90:A9:F7:F0:69:D5
2025-11-20 12:37:07 - 远程修改完成
2025-11-20 12:37:07 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:69:D5
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-20 12:37:07 - 远程sync执行!
2025-11-20 12:37:10 - 远程重启!
2025-11-20 12:37:14 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-20 12:54:55 - 已连接并读取远程MAC: 90:A9:F7:F0:6A:63
2025-11-20 12:54:57 - 远程修改完成
2025-11-20 12:54:57 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:6A:63
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-20 12:54:57 - 远程sync执行!
2025-11-20 12:54:59 - 远程重启!
2025-11-20 12:55:01 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer
2025-11-20 15:32:07 - 连接失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: Connection timed out
2025-11-20 15:32:11 - 连接失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: No route to host
2025-11-20 15:41:59 - 连接失败: SSH错误: ssh: connect to host 10.10.12.12 port 22: Connection timed out
2025-11-20 15:42:06 - 已连接并读取远程MAC: 90:A9:F7:F0:6A:4F
2025-11-20 15:42:08 - 远程修改完成
2025-11-20 15:42:08 - OUTPUT:
BEFORE:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:F0:6A:4F
AFTER:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.12.12
netmask 255.255.255.0
gateway 10.10.12.1
hwaddress ether 90:A9:F7:30:00:00
OK
2025-11-20 15:42:08 - 远程sync执行!
2025-11-20 15:42:09 - 远程重启!
2025-11-20 15:42:11 - 刷新失败: SSH错误: kex_exchange_identification: read: Connection reset by peer

View File

@ -218,9 +218,38 @@ void MainWindow::onModifyClicked() {
log("远程修改失败: " + err);
return;
}
QMessageBox::information(this, "远程修改完成", "已通过SSH修改MAC");
log("远程修改完成");
if (!err.isEmpty()) log(err);
QString syncErr;
bool syncOk = sshClient->execRemoteCommand(host, user, secret, "sync; sync; sync; sleep 1", &syncErr);
if (!syncOk) {
log("远程sync执行!");
} else {
log("已在远程执行sync");
}
QMessageBox::StandardButton ret = QMessageBox::question(
this,
"重启确认",
"远程MAC已更新并已执行sync。是否现在重启远程系统",
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (ret == QMessageBox::Yes) {
QString rebootErr;
bool rebootOk = sshClient->execRemoteCommand(host, user, secret, "reboot", &rebootErr);
if (rebootOk) {
QMessageBox::information(this, "已触发重启", "远程系统正在重启");
log("远程系统已触发重启");
} else {
//QMessageBox::warning(this, "重启失败", rebootErr);
log("远程重启!");
}
} else {
QMessageBox::information(this, "操作完成", "已应用成功,若需生效请稍后手动重启远程系统");
}
onRefreshClicked();
} else {
// 本地修改

View File

@ -493,3 +493,92 @@ bool SshClient::backupRemoteFile(const QString &host,
return true;
}
bool SshClient::execRemoteCommand(const QString &host,
const QString &user,
const QString &password,
const QString &command,
QString *err) {
QString remoteCmd = QString("bash -lc '%1'").arg(escapeSingleQuotes(command));
QString program;
QStringList args;
QStringList baseOpts;
#ifdef Q_OS_WIN
baseOpts << "-o" << "StrictHostKeyChecking=no"
#else
baseOpts << "-o" << "StrictHostKeyChecking=accept-new"
#endif
<< "-o" << QString("UserKnownHostsFile=%1").arg(QDir::homePath() + "/.ssh/known_hosts")
<< "-o" << "ConnectTimeout=10"
<< "-o" << "LogLevel=ERROR"
<< "-T"
<< "-o" << "PreferredAuthentications=password"
<< "-o" << "PubkeyAuthentication=no"
<< "-o" << "KbdInteractiveAuthentication=no"
<< "-o" << "PasswordAuthentication=yes"
<< "-o" << "NumberOfPasswordPrompts=1";
#ifdef Q_OS_WIN
QString sshpass = findExecPreferApp("sshpass");
QString plink = findExecPreferApp("plink");
if (!password.isEmpty() && !sshpass.isEmpty()) {
program = sshpass;
QString sshPath = findExecPreferApp("ssh");
if (sshPath.isEmpty()) sshPath = "ssh";
args = {"-p", password, sshPath};
args << baseOpts << QString("%1@%2").arg(user, host) << remoteCmd;
} else if (!plink.isEmpty()) {
program = plink;
args << "-batch";
if (!password.isEmpty()) args << "-pw" << password;
args << QString("%1@%2").arg(user, host) << remoteCmd;
} else {
if (err) *err = "Windows 未找到支持密码认证的工具sshpass/plink";
return false;
}
#else
if (!password.isEmpty()) {
QString sshpassUnix = QStandardPaths::findExecutable("sshpass");
if (!sshpassUnix.isEmpty()) {
program = sshpassUnix;
args = {"-p", password, "ssh"};
} else {
program = "ssh";
}
} else {
program = "ssh";
}
args << baseOpts << QString("%1@%2").arg(user, host) << remoteCmd;
#endif
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.start(program, args);
if (!p.waitForStarted(10000)) {
if (err) *err = "无法启动SSH进程";
return false;
}
if (!p.waitForFinished(20000)) {
p.kill();
if (err) *err = "SSH命令执行超时";
return false;
}
QString mergedOut = QString::fromLocal8Bit(p.readAllStandardOutput()).trimmed();
if (p.exitCode() != 0) {
if (mergedOut.contains("REMOTE HOST IDENTIFICATION HAS CHANGED")) {
if (removeKnownHost(host)) {
QProcess p2;
p2.setProcessChannelMode(QProcess::MergedChannels);
p2.start(program, args);
if (p2.waitForStarted(10000) && p2.waitForFinished(20000) && p2.exitCode() == 0) {
return true;
}
}
if (err) *err = QString("主机密钥已变化,自动删除失败。\n请手动执行: ssh-keygen -R '%1'").arg(host);
return false;
}
if (err) *err = mergedOut.isEmpty() ? QString("SSH执行失败") : mergedOut;
return false;
}
if (err) *err = mergedOut;
return true;
}

View File

@ -28,4 +28,9 @@ public:
const QString &password,
const QString &filePath,
QString *err);
bool execRemoteCommand(const QString &host,
const QString &user,
const QString &password,
const QString &command,
QString *err);
};