spirit's code expanded (did not catch the TTL-expired case):
...
connect(ping, SIGNAL(readyReadStandardOutput()), SLOT(readResult()));
ping
->start
(QString("ping.exe %1").
arg("192.168.99.99"));
...
void Test::readResult()
{
QProcess *ping
= qobject_cast<QProcess
*>
(sender
());
if (!ping)
return;
QString res
= ping
->readAllStandardOutput
();
if (!res.contains('%'))
return;
const int percentLost = res.section('(', -1).section('%', 0, 0).toInt();
if (percentLost == 100) {
qDebug() << "host not found.";
} else {
// above is basically the same code until here:
if ( res.
contains(QRegExp("=\\d+ms")) ) { qDebug() << "host found." << res; // actual response time from IP
} else {
qDebug() << "host not found." << res; // TTL expired in transit
}
}
}
...
QProcess *ping = new QProcess(this);
connect(ping, SIGNAL(readyReadStandardOutput()), SLOT(readResult()));
ping->start(QString("ping.exe %1").arg("192.168.99.99"));
...
void Test::readResult()
{
QProcess *ping = qobject_cast<QProcess *>(sender());
if (!ping)
return;
QString res = ping->readAllStandardOutput();
if (!res.contains('%'))
return;
const int percentLost = res.section('(', -1).section('%', 0, 0).toInt();
if (percentLost == 100) {
qDebug() << "host not found.";
} else {
// above is basically the same code until here:
if ( res.contains(QRegExp("=\\d+ms")) ) {
qDebug() << "host found." << res; // actual response time from IP
} else {
qDebug() << "host not found." << res; // TTL expired in transit
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks