blob: 8c93c52b5a97c9bbc8d75be90a9237919b27e756 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include "sysInfo.h"
#include <QString>
#include <QTime>
#include <QNetworkInterface>
sysInfo::sysInfo(){
if (debug) qDebug() << "sysInfo created.";
}
sysInfo::~sysInfo(){}
QString sysInfo::getInfo(QString& infoName){
if (debug) qDebug() << "sysInfo : getInfo(" << infoName << ")";
if (infoName == QString("mac"))
return getMACAddress();
else if (infoName == QString("ip"))
return getIPAddress();
// still here? --> error
return "error";
}
QString sysInfo::getMACAddress(){
QNetworkInterface *qNetI = new QNetworkInterface();
QList<QNetworkInterface> list;
list=qNetI->allInterfaces();
QString str;
QString macAddress;
for (int i = 0; i < list.size(); ++i) {
str = list.at(i).name();
macAddress = list.at(i).hardwareAddress();
if (debug) qDebug() << str << " : " << macAddress;
}
// returns only the latest found interface ... to fix
return macAddress;
}
QString sysInfo::getIPAddress(){
QString ipAddress = "";
QNetworkInterface *qNetI = new QNetworkInterface();
QList<QHostAddress> list;
list=qNetI->allAddresses();
for (int i = 0; i < list.size(); ++i) {
ipAddress = list.at(i).toString();
if (debug) qDebug() << "IP Address" << " : " << ipAddress;
}
// returns only the latest found interface ... to fix
return ipAddress;
}
|