Commit 88ad9e2a by “liusq”

修改命令

parent c3dd3878
...@@ -487,27 +487,30 @@ inline bool pingAddress(const QString &address) { ...@@ -487,27 +487,30 @@ inline bool pingAddress(const QString &address) {
QProcess process; QProcess process;
QString program = "ping"; QString program = "ping";
QStringList arguments; QStringList arguments;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// Windows下通常不需要sudo // Windows 下通常不需要 sudo
arguments << "-n" << "1" << address; arguments << "-n" << "1" << address;
#else #else
// 使用sudo // 不使用 sudo
program = "sudo"; arguments << "-c" << "1" << address;
arguments << "ping" << "-c" << "1" << address;
#endif #endif
process.start(program, arguments); process.start(program, arguments);
if (!process.waitForStarted()) { if (!process.waitForStarted()) {
qWarning() << "Failed to start 'ping' process for" << address;
return false; return false;
} }
// 使用较长的超时值,确保进程有足够时间完成 // 使用较长的超时值,确保进程有足够时间完成
if (!process.waitForFinished(3000)) { if (!process.waitForFinished(3000)) {
process.kill(); // 如果超时,强制终止进程 process.kill(); // 如果超时,强制终止进程
qWarning() << "Ping process timed out for" << address;
return false; return false;
} }
QString output(process.readAllStandardOutput()); QString output(process.readAllStandardOutput());
qDebug() << "Ping Output for" << address << ":" << output; // 调试输出
// 简单的 Ping 成功检查逻辑 // 简单的 Ping 成功检查逻辑
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
...@@ -517,7 +520,6 @@ inline bool pingAddress(const QString &address) { ...@@ -517,7 +520,6 @@ inline bool pingAddress(const QString &address) {
#endif #endif
} }
inline QString findReachableIp() { inline QString findReachableIp() {
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
for (const QHostAddress &address : ipAddressesList) { for (const QHostAddress &address : ipAddressesList) {
...@@ -527,7 +529,9 @@ inline QString findReachableIp() { ...@@ -527,7 +529,9 @@ inline QString findReachableIp() {
for (int i = 254; i >= 1; --i) { // 从 254 开始递减 for (int i = 254; i >= 1; --i) { // 从 254 开始递减
QString ip = currentSubnet + QString::number(i); QString ip = currentSubnet + QString::number(i);
qInfo() << "Found findReachableIp IP:" << ip;
if (!pingAddress(ip)) { if (!pingAddress(ip)) {
qInfo() << "ping 不通的ip:" << ip;
return ip; return ip;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment