Commit 39f00f3635fec1c4870a30c4825203f3842aa9a2
1 parent
c838d95d
Exists in
master
adicionado funções get MAC e IP.
Showing
6 changed files
with
84 additions
and
10 deletions
Show diff stats
cacic-teste/cacic-teste.pro
cacic-teste/testcacic.cpp
| 1 | -#include <QProcess> | |
| 2 | -#include <QStringList> | |
| 3 | 1 | #include "testcacic.h" |
| 4 | -#include <iostream> | |
| 5 | 2 | |
| 6 | 3 | QTEST_MAIN(CTestCacic) |
| 7 | 4 | |
| ... | ... | @@ -86,3 +83,11 @@ void CTestCacic::testDeCrypt(){ |
| 86 | 83 | QVERIFY(OCacic.deCrypt(input, key, IV) == "aqui vai a url que sera encriptada"); |
| 87 | 84 | |
| 88 | 85 | } |
| 86 | + | |
| 87 | +void CTestCacic::testpegarIPInterfaceDeRede(){ | |
| 88 | + QVERIFY(OCacicComp.pegarIPInterfaceDeRede() == "10.1.0.89"); | |
| 89 | +} | |
| 90 | + | |
| 91 | +void CTestCacic::testpegarMACInterfaceDeRede(){ | |
| 92 | + QVERIFY(OCacicComp.pegarMACInterfaceDeRede() == "E0:3F:49:E4:70:12"); | |
| 93 | +} | ... | ... |
cacic-teste/testcacic.h
| ... | ... | @@ -2,8 +2,14 @@ |
| 2 | 2 | #define TESTINSTALLCACIC_H |
| 3 | 3 | #include "../src/CACIC_comm.h" |
| 4 | 4 | #include "../src/ccacic.h" |
| 5 | +#include "../src/cacic_computer.h" | |
| 5 | 6 | #include <QtTest/QtTest> |
| 6 | 7 | #include <QDebug> |
| 8 | +#include <QList> | |
| 9 | +#include <QProcess> | |
| 10 | +#include <QStringList> | |
| 11 | +#include <iostream> | |
| 12 | +#include <QHostAddress> | |
| 7 | 13 | |
| 8 | 14 | class CTestCacic : public QObject |
| 9 | 15 | { |
| ... | ... | @@ -14,6 +20,7 @@ public: |
| 14 | 20 | private: |
| 15 | 21 | CacicComm OCacicComm; |
| 16 | 22 | CCacic OCacic; |
| 23 | + CACIC_Computer OCacicComp; | |
| 17 | 24 | QString testPath; |
| 18 | 25 | QString testIniPath; |
| 19 | 26 | |
| ... | ... | @@ -31,6 +38,8 @@ private slots: |
| 31 | 38 | void testCreateFolder(); |
| 32 | 39 | void testDeleteFolder(); |
| 33 | 40 | void testDeleteFile(); |
| 41 | + void testpegarIPInterfaceDeRede(); | |
| 42 | + void testpegarMACInterfaceDeRede(); | |
| 34 | 43 | }; |
| 35 | 44 | |
| 36 | 45 | #endif // TESTINSTALLCACIC_H | ... | ... |
install-cacic/install-cacic.pro
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | #------------------------------------------------- |
| 6 | 6 | |
| 7 | 7 | QT += core |
| 8 | - | |
| 8 | +QT += network | |
| 9 | 9 | QT -= gui |
| 10 | 10 | |
| 11 | 11 | TARGET = install-cacic |
| ... | ... | @@ -16,9 +16,11 @@ TEMPLATE = app |
| 16 | 16 | |
| 17 | 17 | SOURCES += main.cpp \ |
| 18 | 18 | installcacic.cpp \ |
| 19 | - ../src/ccacic.cpp | |
| 19 | + ../src/ccacic.cpp \ | |
| 20 | + ../src/cacic_computer.cpp | |
| 20 | 21 | |
| 21 | 22 | HEADERS += \ |
| 22 | 23 | installcacic.h \ |
| 23 | 24 | ../src/CACIC_comm.h \ |
| 24 | - ../src/ccacic.h | |
| 25 | + ../src/ccacic.h \ | |
| 26 | + ../src/cacic_computer.h | ... | ... |
src/cacic_computer.cpp
| 1 | 1 | #include "cacic_computer.h" |
| 2 | 2 | |
| 3 | 3 | CACIC_Computer::CACIC_Computer(QObject *parent) : |
| 4 | - QObject(parent) | |
| 4 | + QObject(parent) | |
| 5 | 5 | { |
| 6 | 6 | } |
| 7 | + | |
| 8 | +void CACIC_Computer::setIp(const std::string &value) | |
| 9 | +{ | |
| 10 | + ip = value; | |
| 11 | +} | |
| 12 | + | |
| 13 | +void CACIC_Computer::setMac(const std::string &value) | |
| 14 | +{ | |
| 15 | + mac = value; | |
| 16 | +} | |
| 17 | + | |
| 18 | +void CACIC_Computer::setOs(const std::string &value) | |
| 19 | +{ | |
| 20 | + os = value; | |
| 21 | +} | |
| 22 | + | |
| 23 | +std::string CACIC_Computer::pegarIPInterfaceDeRede() { | |
| 24 | + QNetworkInterface interface; | |
| 25 | + QList<QHostAddress> result; | |
| 26 | + QList<QHostAddress> IpList = interface.allAddresses(); | |
| 27 | + for (int i = 0; i < IpList.size(); i++){ | |
| 28 | + if((!IpList.at(i).isLoopback()) & (IpList.at(i).scopeId() == Q_NULLPTR)){ | |
| 29 | + result.append(IpList.at(i)); | |
| 30 | + setIp(IpList.at(i).toString().toStdString()); | |
| 31 | + break; | |
| 32 | + } | |
| 33 | + } | |
| 34 | + return result.at(0).toString().toStdString() ; | |
| 35 | +} | |
| 36 | + | |
| 37 | + | |
| 38 | +std::string CACIC_Computer::pegarMACInterfaceDeRede(){ | |
| 39 | + foreach (const QNetworkInterface &ni, QNetworkInterface::allInterfaces()) { | |
| 40 | + if (!(ni.flags() & ni.IsLoopBack)){ | |
| 41 | + //qDebug() << ni.hardwareAddress(); | |
| 42 | + return ni.hardwareAddress().toStdString(); | |
| 43 | + break; | |
| 44 | + } | |
| 45 | + } | |
| 46 | +} | ... | ... |
src/cacic_computer.h
| ... | ... | @@ -2,17 +2,33 @@ |
| 2 | 2 | #define CACIC_COMPUTER_H |
| 3 | 3 | |
| 4 | 4 | #include <QObject> |
| 5 | +#include <QStringList> | |
| 6 | +#include <QtSerialPort/QtSerialPort> | |
| 7 | +#include <QtSerialPort/QSerialPortInfo> | |
| 8 | +#include <QtNetwork/QtNetwork> | |
| 9 | +#include <QHostAddress> | |
| 5 | 10 | |
| 6 | 11 | class CACIC_Computer : public QObject |
| 7 | 12 | { |
| 8 | - Q_OBJECT | |
| 13 | + Q_OBJECT | |
| 9 | 14 | public: |
| 10 | - explicit CACIC_Computer(QObject *parent = 0); | |
| 15 | + explicit CACIC_Computer(QObject *parent = 0); | |
| 16 | + std::string pegarIPInterfaceDeRede(); | |
| 17 | + std::string pegarMACInterfaceDeRede(); | |
| 18 | + void setIp(const std::string &value); | |
| 19 | + void setMac(const std::string &value); | |
| 20 | + void setOs(const std::string &value); | |
| 21 | + | |
| 22 | +private: | |
| 23 | + std::string ip; | |
| 24 | + std::string mac; | |
| 25 | + std::string os; | |
| 11 | 26 | |
| 12 | 27 | signals: |
| 13 | 28 | |
| 14 | 29 | public slots: |
| 15 | 30 | |
| 31 | + | |
| 16 | 32 | }; |
| 17 | 33 | |
| 18 | 34 | #endif // CACIC_COMPUTER_H | ... | ... |