Skip to content
Snippets Groups Projects
Commit 5add3e78 authored by borsitsb's avatar borsitsb
Browse files

added network commands research

parent 702b4709
No related branches found
No related tags found
No related merge requests found
......@@ -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];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment