Commit 1893e60d by 郭峰

Merge branch 'feature-1007488' into 'release'

修改ping命令-03

See merge request !43
parents e14f599a 225f0db7
...@@ -454,28 +454,22 @@ inline bool GetNetworkInfoByQNetworkInterface(QString &mac, QString &subnetMask, ...@@ -454,28 +454,22 @@ inline bool GetNetworkInfoByQNetworkInterface(QString &mac, QString &subnetMask,
subnetMask = entry.netmask().toString(); subnetMask = entry.netmask().toString();
// 获取网关地址 // 获取网关地址
QProcess process; QFile file("/proc/net/route");
process.start("sudo", QStringList() << "/sbin/ip" << "route"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
if (!process.waitForStarted()) { qInfo() << "Failed to open /proc/net/route file.";
qInfo() << "Failed to start 'ip route' process.";
continue; continue;
} }
if (!process.waitForFinished()) { QTextStream in(&file);
process.kill(); while (!in.atEnd()) {
qInfo() << "Process 'ip route' timed out."; QString line = in.readLine();
continue; QStringList parts = line.split(QRegExp("\\s+"));
} if (parts.size() >= 3 && parts[1] == "00000000") {
gateway = parts[2];
QString output = process.readAllStandardOutput(); gateway = gateway.mid(6, 2) + ":" + gateway.mid(4, 2) + ":" + gateway.mid(2, 2) + ":" + gateway.mid(0, 2);
QStringList lines = output.split('\n'); gateway = gateway.replace(":", ".");
foreach (QString line, lines) { gateway = QHostAddress(gateway).toString();
if (line.startsWith("default via")) { return true;
QStringList parts = line.split(QRegExp("\\s+"));
if (parts.size() >= 3) {
gateway = parts[2];
return true;
}
} }
} }
} }
......
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