blob: 266c210f279bb697ab73814833d757473b6058ee (
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
46
47
48
|
#include "sysInfo.h"
#include <QString>
#include <QTime>
#include <QNetworkInterface>
//static int eth0_index = 0;
// ------------------------------------------------------------------------------------------------
sysInfo::sysInfo(){
if (debug) qDebug() << "sysInfo created.";
// Maybe search for eth0, etc
}
// ------------------------------------------------------------------------------------------------
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?
return "info_error";
}
// ------------------------------------------------------------------------------------------------
QString sysInfo::getMACAddress(){
/* Returns MAC address of eth0 for now. */
QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0"));
if (!qni.isValid()){
if (debug) qDebug() << "No interface matching \"eth0\" found.";
return "no_eth0";
}
//eth0_index = qni.index();
return qni.hardwareAddress();
}
// ------------------------------------------------------------------------------------------------
QString sysInfo::getIPAddress(){
// Again for eth0 only at the moment.
// TODO: this doesn't quite work yet...
QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0"));
QList<QHostAddress> addrlist = qni.allAddresses();
foreach(QHostAddress addr, addrlist){
if (addr.protocol() == QAbstractSocket::IPv6Protocol)
qDebug() << "eth0: IPv4 Address: " << addr.toString();
return addr.toString();
}
// still here?
return "ip_error";
}
|