I am currently using this code to extract the ping of the target system. However, it still works only under Linux and probably depends on the locale settings. To add support for windows is likely to be even more difficult. Is there an easy way or library to get the ping of the target system? I mainly work with Qt, so it would be ideal if I could work with QSockets.
#ifndef _WIN32 QProcess ping; ping.start("ping", QStringList() << "-c 1" << m_sHostName); if(ping.waitForFinished(250) ) { while(ping.canReadLine()) { QString line = ping.readLine(); if(line.contains("time=")) { int iStart = line.indexOf("time=") + 5; int iStop = line.indexOf(" ms"); QStringRef latency(&line, iStart, iStop-iStart); m_vNetwork_s.append(time_s); m_vLatency_ms.append(QString(latency.toLocal8Bit()).toDouble()); break; } } } #endif
c ++ qt ping qtnetwork qabstractsocket
dgrat
source share