修复Ping的BUG

Signed-off-by: fong <wuwenfengmi@outlook.com>
This commit is contained in:
fong
2024-02-01 10:55:59 +08:00
parent ee9b9417ab
commit f3016c7b54
+5 -3
View File
@@ -26,13 +26,15 @@ quint32 ipv4str_to_int(const QString& ipstr)
}
}
bool Ping(QString strPingIP)
bool Ping(QString strPingIP,qint16 timeout)
{
QProcess pingProcess;
QString strArg = "ping " + strPingIP + " -n 1 -i 2";
QString strArg = "ping " + strPingIP + " -n 2 -w "+QString("%1").arg(timeout);// + " -n 1 -i 2";
qDebug()<<strArg;
pingProcess.start(strArg, QIODevice::ReadOnly);
pingProcess.waitForFinished(-1);
QString p_stdout = QString::fromLocal8Bit(pingProcess.readAllStandardOutput());
qDebug()<<p_stdout;
return p_stdout.contains("TTL=");
}
@@ -48,7 +50,7 @@ void trytryping::run()
QString ip=this->ipstr;
if(Ping(ip))
if(Ping(ip,this->timeout))
{
emit connect_ok(ip);
}