Commit ec33ae2ce665001ca9d56c123e67ba8e2060e1d5
1 parent
05f8f16f
Exists in
master
Retornando lista ao pegar ip, mac e nome.
Showing
7 changed files
with
78 additions
and
48 deletions
Show diff stats
cacic-teste/cacic-teste.pro
| @@ -9,6 +9,7 @@ QT += network | @@ -9,6 +9,7 @@ QT += network | ||
| 9 | 9 | ||
| 10 | TARGET = cacic-teste | 10 | TARGET = cacic-teste |
| 11 | CONFIG -= app_bundle | 11 | CONFIG -= app_bundle |
| 12 | +CONFIG += c++11 | ||
| 12 | TEMPLATE = app | 13 | TEMPLATE = app |
| 13 | win32 { | 14 | win32 { |
| 14 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp | 15 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp |
cacic-teste/testcacic.cpp
| @@ -85,10 +85,14 @@ void CTestCacic::testDeCrypt(){ | @@ -85,10 +85,14 @@ void CTestCacic::testDeCrypt(){ | ||
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | void CTestCacic::testInterfaceDeRede(){ | 87 | void CTestCacic::testInterfaceDeRede(){ |
| 88 | -// qDebug() << QString::fromStdString(OCacicComp.getIp()); | 88 | +// qDebug() << QString::fromStdString(OCacicComp.getNetworkInterface().at(0).at(0)); |
| 89 | QVERIFY(!OCacicComp.getNetworkInterface().empty()); | 89 | QVERIFY(!OCacicComp.getNetworkInterface().empty()); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | void CTestCacic::testpegarOS(){ | 92 | void CTestCacic::testpegarOS(){ |
| 93 | - QVERIFY(OCacicComp.getOs() == "Windows_NT"); | 93 | + QVERIFY((OCacicComp.getOs() == "Windows_NT") || (OCacicComp.getOs() == "linux")); |
| 94 | } | 94 | } |
| 95 | + | ||
| 96 | +//void CTestCacic::testJson(){ | ||
| 97 | +// OCacic.readJson(); | ||
| 98 | +//} |
cacic-teste/testcacic.h
| @@ -40,6 +40,7 @@ private slots: | @@ -40,6 +40,7 @@ private slots: | ||
| 40 | void testDeleteFile(); | 40 | void testDeleteFile(); |
| 41 | void testInterfaceDeRede(); | 41 | void testInterfaceDeRede(); |
| 42 | void testpegarOS(); | 42 | void testpegarOS(); |
| 43 | +// void testJson(); | ||
| 43 | }; | 44 | }; |
| 44 | 45 | ||
| 45 | #endif // TESTINSTALLCACIC_H | 46 | #endif // TESTINSTALLCACIC_H |
src/cacic_computer.cpp
| @@ -3,41 +3,44 @@ | @@ -3,41 +3,44 @@ | ||
| 3 | CACIC_Computer::CACIC_Computer(QObject *parent) : | 3 | CACIC_Computer::CACIC_Computer(QObject *parent) : |
| 4 | QObject(parent) | 4 | QObject(parent) |
| 5 | { | 5 | { |
| 6 | - ip = pegarIPInterfaceDeRede(); | ||
| 7 | - mac = pegarMACInterfaceDeRede(); | 6 | + os = pegarOS(); |
| 7 | + networkInterface = networkInterfacesRunning(); | ||
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | -std::string CACIC_Computer::pegarIPInterfaceDeRede() { | ||
| 11 | - QNetworkInterface interface; | ||
| 12 | - QList<QHostAddress> IpList = interface.allAddresses(); | ||
| 13 | - for (int i = 0; i < IpList.size(); i++){ | ||
| 14 | - if((!IpList.at(i).isLoopback()) & (IpList.at(i).scopeId() == "")){ | ||
| 15 | - return IpList.at(i).toString().toStdString(); | 10 | +QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){ |
| 11 | + QNetworkInterface interface; | ||
| 12 | + QList<std::string> lista; | ||
| 13 | + QList<QList<std::string>> todasInterfaces; | ||
| 14 | + | ||
| 15 | + foreach (QNetworkInterface in, interface.allInterfaces()) { | ||
| 16 | + if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) & | ||
| 17 | + !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) & | ||
| 18 | + (bool)(in.flags() & QNetworkInterface::IsRunning)){ | ||
| 19 | + lista.append(in.humanReadableName().toStdString()); | ||
| 20 | + lista.append(in.hardwareAddress().toStdString()); | ||
| 21 | + foreach (QNetworkAddressEntry ae, in.addressEntries()){ | ||
| 22 | + if (ae.ip().scopeId() == ""){ | ||
| 23 | + lista.append(ae.ip().toString().toStdString()); | ||
| 24 | + } else { | ||
| 25 | + lista.append(ae.ip().toString().toStdString()); | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | + todasInterfaces.append(lista); | ||
| 29 | + lista.clear(); | ||
| 16 | } | 30 | } |
| 17 | } | 31 | } |
| 18 | - return ""; | ||
| 19 | -} | ||
| 20 | - | ||
| 21 | - | ||
| 22 | -std::string CACIC_Computer::pegarMACInterfaceDeRede(){ | ||
| 23 | - foreach (const QNetworkInterface &ni, QNetworkInterface::allInterfaces()) { | ||
| 24 | - if (!(ni.flags() & ni.IsLoopBack)){ | ||
| 25 | - //qDebug() << ni.hardwareAddress(); | ||
| 26 | - return ni.hardwareAddress().toStdString(); | ||
| 27 | - } | ||
| 28 | - } | ||
| 29 | - return "ERROR MAC"; | 32 | + return todasInterfaces; |
| 30 | } | 33 | } |
| 31 | 34 | ||
| 32 | std::string CACIC_Computer::pegarOS(){ | 35 | std::string CACIC_Computer::pegarOS(){ |
| 33 | QString text; | 36 | QString text; |
| 34 | - qint32 x=0; | ||
| 35 | - //QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); | ||
| 36 | QStringList environment = QProcess::systemEnvironment(); | 37 | QStringList environment = QProcess::systemEnvironment(); |
| 37 | -// foreach (text, environment) { | ||
| 38 | -// qDebug() << x << sear; | ||
| 39 | -// x++; | ||
| 40 | -// } | 38 | + foreach (text, environment) { |
| 39 | + if (text.contains("OS=", Qt::CaseInsensitive)){ | ||
| 40 | + return text.mid(text.indexOf("=")+1).toStdString(); | ||
| 41 | + } | ||
| 42 | + //implementar o if pra quando for linux. | ||
| 43 | + } | ||
| 41 | return ""; | 44 | return ""; |
| 42 | } | 45 | } |
| 43 | 46 | ||
| @@ -45,17 +48,14 @@ std::string CACIC_Computer::pegarOS(){ | @@ -45,17 +48,14 @@ std::string CACIC_Computer::pegarOS(){ | ||
| 45 | * getters/setters | 48 | * getters/setters |
| 46 | */ | 49 | */ |
| 47 | 50 | ||
| 48 | -std::string CACIC_Computer::getIp() const | ||
| 49 | -{ | ||
| 50 | - return ip; | ||
| 51 | -} | ||
| 52 | -std::string CACIC_Computer::getMac() const | ||
| 53 | -{ | ||
| 54 | - return mac; | ||
| 55 | -} | ||
| 56 | std::string CACIC_Computer::getOs() const | 51 | std::string CACIC_Computer::getOs() const |
| 57 | { | 52 | { |
| 58 | return os; | 53 | return os; |
| 59 | } | 54 | } |
| 55 | +QList<QList<std::string>> CACIC_Computer::getNetworkInterface() const | ||
| 56 | +{ | ||
| 57 | + return networkInterface; | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | 60 | ||
| 61 | 61 |
src/cacic_computer.h
| @@ -6,25 +6,21 @@ | @@ -6,25 +6,21 @@ | ||
| 6 | #include <QtSerialPort/QtSerialPort> | 6 | #include <QtSerialPort/QtSerialPort> |
| 7 | #include <QtSerialPort/QSerialPortInfo> | 7 | #include <QtSerialPort/QSerialPortInfo> |
| 8 | #include <QtNetwork/QtNetwork> | 8 | #include <QtNetwork/QtNetwork> |
| 9 | -#include <QHostAddress> | ||
| 10 | 9 | ||
| 11 | class CACIC_Computer : public QObject | 10 | class CACIC_Computer : public QObject |
| 12 | { | 11 | { |
| 13 | Q_OBJECT | 12 | Q_OBJECT |
| 14 | public: | 13 | public: |
| 15 | - explicit CACIC_Computer(QObject *parent = 0); | ||
| 16 | - std::string pegarIPInterfaceDeRede(); | ||
| 17 | - std::string pegarMACInterfaceDeRede(); | ||
| 18 | - std::string pegarOS(); | ||
| 19 | - void setOs(const std::string &value); | ||
| 20 | - std::string getIp() const; | ||
| 21 | - std::string getMac() const; | ||
| 22 | - std::string getOs() const; | 14 | + explicit CACIC_Computer(QObject *parent = 0); |
| 15 | + | ||
| 16 | + std::string pegarOS(); | ||
| 17 | + std::string getOs() const; | ||
| 18 | + QList<QList<std::string>> getNetworkInterface() const; | ||
| 19 | + QList<QList<std::string>> networkInterfacesRunning(); | ||
| 23 | 20 | ||
| 24 | private: | 21 | private: |
| 25 | - std::string ip; | ||
| 26 | - std::string mac; | ||
| 27 | - std::string os; | 22 | + QList<QList<std::string>> networkInterface; |
| 23 | + std::string os; | ||
| 28 | 24 | ||
| 29 | signals: | 25 | signals: |
| 30 | 26 |
src/ccacic.cpp
| @@ -149,6 +149,33 @@ QString CCacic::deCrypt(QString str_in, QString key, QString iv) { | @@ -149,6 +149,33 @@ QString CCacic::deCrypt(QString str_in, QString key, QString iv) { | ||
| 149 | return QString::fromStdString(str_out).toLocal8Bit(); | 149 | return QString::fromStdString(str_out).toLocal8Bit(); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | +//void CCacic::readJson() | ||
| 153 | +//{ | ||
| 154 | +// QString val; | ||
| 155 | +// QFile file; | ||
| 156 | +// file.setFileName("e:/Lightbase/teste.json"); | ||
| 157 | +// file.open(QIODevice::ReadOnly | QIODevice::Text); | ||
| 158 | +// val = file.readAll(); | ||
| 159 | +// file.close(); | ||
| 160 | +// qWarning() << val; | ||
| 161 | +// QJsonDocument d = QJsonDocument::fromJson(val.toUtf8()); | ||
| 162 | +// QJsonObject sett2 = d.object(); | ||
| 163 | +// QJsonValue value = sett2.value(QString("appName")); | ||
| 164 | +// qWarning() << value; | ||
| 165 | +// QJsonObject item = value.toObject(); | ||
| 166 | +// qWarning() << tr("QJsonObject of description: ") << item; | ||
| 167 | + | ||
| 168 | +// /* incase of string value get value and convert into string*/ | ||
| 169 | +// qWarning() << tr("QJsonObject[appName] of description: ") << item["description"]; | ||
| 170 | +// QJsonValue subobj = item["description"]; | ||
| 171 | +// qWarning() << subobj.toString(); | ||
| 172 | + | ||
| 173 | +// /* incase of array get array and convert into string*/ | ||
| 174 | +// qWarning() << tr("QJsonObject[appName] of value: ") << item["imp"]; | ||
| 175 | +// QJsonArray test = item["imp"].toArray(); | ||
| 176 | +// qWarning() << test[1].toString(); | ||
| 177 | +//} | ||
| 178 | + | ||
| 152 | /*Getters/Setters | 179 | /*Getters/Setters |
| 153 | * Begin: | 180 | * Begin: |
| 154 | */ | 181 | */ |
src/ccacic.h
| @@ -30,6 +30,7 @@ public: | @@ -30,6 +30,7 @@ public: | ||
| 30 | bool createFolder(QString path); | 30 | bool createFolder(QString path); |
| 31 | bool deleteFolder(QString path); | 31 | bool deleteFolder(QString path); |
| 32 | bool deleteFile(QString path); | 32 | bool deleteFile(QString path); |
| 33 | +// void readJson(); | ||
| 33 | 34 | ||
| 34 | //Geters/seters: | 35 | //Geters/seters: |
| 35 | 36 |