Commit 88ad9e2a by “liusq”

修改命令

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