From 5add3e78fc5c53e6a68c0fc073d7c2bc6319bf80 Mon Sep 17 00:00:00 2001 From: Botond Borsits <borsitsb@sch.bme.hu> Date: Sun, 9 Aug 2015 14:16:45 +0000 Subject: [PATCH] added network commands research --- include/Diagnostic.hpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/include/Diagnostic.hpp b/include/Diagnostic.hpp index d19cb51..1ce8bcf 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]; -- GitLab