diff --git a/include/Diagnostic.hpp b/include/Diagnostic.hpp index d19cb51983c7f4690c3ff1d916731fd2bd920492..1ce8bcff1d3dc0541fb60e62614b83fe1bc1ee8d 100644 --- a/include/Diagnostic.hpp +++ b/include/Diagnostic.hpp @@ -5,6 +5,7 @@ #include <QRegExp> #include <QCoreApplication> #include <QtNetwork/QNetworkInterface> +#include <QSysInfo> #ifndef DIAGNOSTIC_HPP #define DIAGNOSTIC_HPP @@ -14,31 +15,40 @@ class Diagnostic { typedef QString (*diagFn_t)(); public: - static const int funcsLen = 3; + static const int funcsLen = 4; diagFn_t funcs[funcsLen]; Diagnostic(){ funcs[0] = getRoutingInfo; - funcs[1] = getPingGateway; - funcs[2] = getInterfaceInfo; + funcs[1] = getOsInfo; + funcs[2] = getPingGateway; + funcs[3] = getInterfaceInfo; + } + + static QString getOsInfo() + { + // Windows: http://www.windows-commandline.com/find-windows-os-version-from-command/ + // Linux: http://superuser.com/questions/11008/how-do-i-find-out-what-version-of-linux-im-running + // I think the best way on linux is: uname -a + // Mac: http://superuser.com/questions/75166/how-to-find-out-mac-os-x-version-from-terminal + // The best way on Mac: sw_vers + return QString("- - - OS version - - - \nOS version"); } static QString getRoutingInfo(){ + // Useful commands: https://kb.wisc.edu/ns/page.php?id=12364 FILE *cmdHandle; - QString ipAddr("- - - Default Gateway - - - \n"); + QString ipAddr("- - - Routing tables - - - \n"); #if defined( Q_OS_WIN ) - // original command: route print -4 | findstr /r "[^0-9]0\.0\.0\.0" cmdHandle = popen( - "route print -4 | findstr /r \"[^0-9]0\\.0\\.0\\.0\" ", "r" + "netsh interface ipv4 show route", "r" ); #elif defined ( Q_OS_LINUX ) - // a guess: netstat -rn | grep "^0\.0\.0\.0" | awk '{print $2}' - // w/o awk: netstat -rn | sed -rn 's/^0\.0\.0\.0\s+([^ ]+).*/\1/p' cmdHandle = popen( - "netstat -rn | sed -rn 's/^0\.0\.0\.0\s+([^ ]+).*/\1/p'", "r" + "netstat -A inet -rn", "r" ); #else -#error "We do not support gateway command for this OS." +#error "Sorry, we do not support this OS!" #endif const int BUFFSIZE = 256; char buffer[BUFFSIZE];