diff --git a/PacketSniffer.pro b/PacketSniffer.pro index 3647ee9..d0c5282 100644 --- a/PacketSniffer.pro +++ b/PacketSniffer.pro @@ -5,7 +5,7 @@ #------------------------------------------------- QT += core gui - +QT += network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = PacketSniffer diff --git a/PacketSniffer.pro.user b/PacketSniffer.pro.user index 3a0df46..2ee043c 100644 --- a/PacketSniffer.pro.user +++ b/PacketSniffer.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {bd8350d0-b7b6-4893-a3c3-d2e2b4754154} + {647b44e5-6cdd-4f0f-b09f-40dfcb504175} ProjectExplorer.Project.ActiveTarget @@ -34,7 +34,7 @@ 4 false 80 - false + true true 1 true @@ -46,221 +46,240 @@ 8 true 1 - false + true true - false + true + *.md, *.MD, Makefile false + true ProjectExplorer.Project.PluginSettings - + + + true + true + true + true + true + + + 0 + true + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + ProjectExplorer.Project.Target.0 - Desktop Qt 5.8.0 GCC 64bit - Desktop Qt 5.8.0 GCC 64bit - qt.58.gcc_64_kit + Desktop + Desktop + Desktop + {69a14e03-55c5-4f22-8d69-454f14922e25} 0 0 0 - /home/mark/Desktop/code/git/build-PacketSniffer-Desktop_Qt_5_8_0_GCC_64bit-Debug + true + 0 + /home/zero/LinuxNetworkingPrograming/packet-parser/build-PacketSniffer-Desktop-Debug + /home/zero/LinuxNetworkingPrograming/packet-parser/build-PacketSniffer-Desktop-Debug true - qmake - QtProjectManager.QMakeBuildStep - true false - false - false + true - Make - Qt4ProjectManager.MakeStep - - -w - -r - + false + false 2 Build - + Build ProjectExplorer.BuildSteps.Build true - Make - Qt4ProjectManager.MakeStep - - -w - -r - + true clean + false 1 Clean - + Clean ProjectExplorer.BuildSteps.Clean 2 false + - Debug - + Debug Qt4ProjectManager.Qt4BuildConfiguration 2 - true + 2 + 2 - /home/mark/Desktop/code/git/build-PacketSniffer-Desktop_Qt_5_8_0_GCC_64bit-Release + true + 2 + /home/zero/LinuxNetworkingPrograming/packet-parser/build-PacketSniffer-Desktop-Release + /home/zero/LinuxNetworkingPrograming/packet-parser/build-PacketSniffer-Desktop-Release true - qmake - QtProjectManager.QMakeBuildStep - false false - false - false + true - Make - Qt4ProjectManager.MakeStep - - -w - -r - + false + false 2 Build - + Build ProjectExplorer.BuildSteps.Build true - Make - Qt4ProjectManager.MakeStep - - -w - -r - + true clean + false 1 Clean - + Clean ProjectExplorer.BuildSteps.Clean 2 false + - Release - + Release Qt4ProjectManager.Qt4BuildConfiguration 0 - true + 2 + 2 - /home/mark/Desktop/code/git/build-PacketSniffer-Desktop_Qt_5_8_0_GCC_64bit-Profile + true + 0 + /home/zero/LinuxNetworkingPrograming/packet-parser/build-PacketSniffer-Desktop-Profile + /home/zero/LinuxNetworkingPrograming/packet-parser/build-PacketSniffer-Desktop-Profile true - qmake - QtProjectManager.QMakeBuildStep - true false - true - false + true - Make - Qt4ProjectManager.MakeStep - - -w - -r - + false + false 2 Build - + Build ProjectExplorer.BuildSteps.Build true - Make - Qt4ProjectManager.MakeStep - - -w - -r - + true clean + false 1 Clean - + Clean ProjectExplorer.BuildSteps.Clean 2 false + - Profile - + Profile Qt4ProjectManager.Qt4BuildConfiguration 0 - true + 2 + 0 3 0 Deploy - + Deploy ProjectExplorer.BuildSteps.Deploy 1 - Deploy locally - + + false ProjectExplorer.DefaultDeployConfiguration 1 + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 false false 1000 @@ -275,6 +294,7 @@ 0.01 10 true + kcachegrind 1 25 @@ -300,23 +320,22 @@ 13 14 + 2 - PacketSniffer - - Qt4ProjectManager.Qt4RunConfiguration:/home/mark/Desktop/code/git/PacketSniffer/PacketSniffer.pro - true - - PacketSniffer.pro - false - - /home/mark/Desktop/code/git/build-PacketSniffer-Desktop_Qt_5_8_0_GCC_64bit-Debug - 3768 + Qt4ProjectManager.Qt4RunConfiguration:/home/zero/LinuxNetworkingPrograming/packet-parser/PacketSniffer/PacketSniffer.pro + /home/zero/LinuxNetworkingPrograming/packet-parser/PacketSniffer/PacketSniffer.pro + + false + false true + true false false true + + /home/zero/LinuxNetworkingPrograming/packet-parser/build-PacketSniffer-Desktop-Debug 1 @@ -327,10 +346,10 @@ ProjectExplorer.Project.Updater.FileVersion - 18 + 22 Version - 18 + 22 diff --git a/PacketSniffer.pro.user.bd8350d.4.8-pre1 b/PacketSniffer.pro.user.bd8350d.4.8-pre1 new file mode 100644 index 0000000..3a0df46 --- /dev/null +++ b/PacketSniffer.pro.user.bd8350d.4.8-pre1 @@ -0,0 +1,336 @@ + + + + + + EnvironmentId + {bd8350d0-b7b6-4893-a3c3-d2e2b4754154} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + false + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + false + true + false + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.8.0 GCC 64bit + Desktop Qt 5.8.0 GCC 64bit + qt.58.gcc_64_kit + 0 + 0 + 0 + + /home/mark/Desktop/code/git/build-PacketSniffer-Desktop_Qt_5_8_0_GCC_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/mark/Desktop/code/git/build-PacketSniffer-Desktop_Qt_5_8_0_GCC_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/mark/Desktop/code/git/build-PacketSniffer-Desktop_Qt_5_8_0_GCC_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + PacketSniffer + + Qt4ProjectManager.Qt4RunConfiguration:/home/mark/Desktop/code/git/PacketSniffer/PacketSniffer.pro + true + + PacketSniffer.pro + false + + /home/mark/Desktop/code/git/build-PacketSniffer-Desktop_Qt_5_8_0_GCC_64bit-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/mainwindow.cpp b/mainwindow.cpp index f52a4b7..938a86c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,18 +1,20 @@ #include #include - +#include #include #include #include #include +#include + #include #include #include #include "mainwindow.h" #include "ui_mainwindow.h" - +extern MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -53,6 +55,13 @@ MainWindow::MainWindow(QWidget *parent) : ui->pauseCaptureButton->setEnabled(false); ui->deleteCaptureButton->setEnabled(false); + QNetworkInterface interface; + QList IpList = interface.allInterfaces(); + for (int i = 0; i < IpList.size(); i++){ + + qDebug() << "Interface " << i << ":" << IpList.at(i).humanReadableName(); + ui->deviceBox->addItem(IpList.at(i).humanReadableName()); + } packetSnifferThread = NULL; isSaved = false; } @@ -69,9 +78,10 @@ MainWindow::~MainWindow(){ } void MainWindow::on_startCaptureButton_clicked(){ + device = ui->deviceBox->currentText().toStdString(); //If this is the first capture, or if the previous capture was deleted, create a new PacketSnifferThread if(packetSnifferThread == NULL){ - packetSnifferThread = new PacketSnifferThread(packetModel, ui->statusBar); + packetSnifferThread = new PacketSnifferThread(packetModel, ui->statusBar,device); } //Disable and enable various buttons @@ -79,7 +89,7 @@ void MainWindow::on_startCaptureButton_clicked(){ ui->stopCaptureButton->setEnabled(true); ui->pauseCaptureButton->setEnabled(true); ui->deleteCaptureButton->setEnabled(false); - + //Start the thread packetSnifferThread->start(); ui->statusBar->showMessage(QString("Packet capture started.")); @@ -264,15 +274,15 @@ void MainWindow::on_actionSave_triggered(){ void MainWindow::on_actionNew_Capture_triggered(){ if(packetSnifferThread == NULL){ //No capture is running, and nothing to save - packetSnifferThread = new PacketSnifferThread(packetModel, ui->statusBar); + packetSnifferThread = new PacketSnifferThread(packetModel, ui->statusBar,device); } else if(packetSnifferThread->isRunning()){ //A capture is still running - ui->statusBar->showMessage("Please stop the current capture."); + ui->statusBar->showMessage("Please stop the capture."); } else if(isSaved == false){ //The capture is not running, but isnt saved ui->deleteCaptureButton->click(); if(packetSnifferThread == NULL){ - packetSnifferThread = new PacketSnifferThread(packetModel, ui->statusBar); + packetSnifferThread = new PacketSnifferThread(packetModel, ui->statusBar,device); } } else{ @@ -298,7 +308,7 @@ void MainWindow::on_actionOpen_triggered(){ ui->statusBar->showMessage("No file selected."); return; } - packetSnifferThread = new PacketSnifferThread(packetModel, fileName, ui->statusBar); + packetSnifferThread = new PacketSnifferThread(packetModel, fileName, ui->statusBar,device); isSaved = true; /* @@ -384,3 +394,10 @@ void MainWindow::on_actionPause_triggered(){ void MainWindow::on_actionClear_triggered(){ ui->deleteCaptureButton->click(); } + +/* +void MainWindow::none(){ + + +} +*/ diff --git a/mainwindow.h b/mainwindow.h index 35e8289..d716a48 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -36,6 +36,7 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + std::string device = "wlo1"; private slots: void on_startCaptureButton_clicked(); //Start the packet capture diff --git a/mainwindow.ui b/mainwindow.ui index 85ca225..38a0994 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -22,7 +22,7 @@ - + gridline-color:black; @@ -35,23 +35,6 @@ - - - - <html><head/><body><p>Enter your filter text here, a regular expression can be used</p></body></html> - - - Filter: - - - - - - - Enter filter text here - - - @@ -72,8 +55,8 @@ - - + + 30 @@ -81,19 +64,36 @@ - <html><head/><body><p>Stop capturing packets</p></body></html> + <html><head/><body><p>Delete the current capture (not available when capturing or when there is nothing to delete)</p></body></html> - :/images/stop_capture_button.png:/images/stop_capture_button.png + :/images/trash_button.png:/images/trash_button.png - - + + + + <html><head/><body><p>Enter your filter text here, a regular expression can be used</p></body></html> + + + Filter: + + + + + + + Enter filter text here + + + + + 30 @@ -101,19 +101,19 @@ - <html><head/><body><p>Clear Filter</p></body></html> + <html><head/><body><p>Pause the capturing of packets, can be resumed later (To clear the current capture, click the garbage icon to the right of this button)</p></body></html> - :/images/clear_filter_button.png:/images/clear_filter_button.png + :/images/pause_button.png:/images/pause_button.png - - + + 30 @@ -121,19 +121,19 @@ - <html><head/><body><p>Pause the capturing of packets, can be resumed later (To clear the current capture, click the garbage icon to the right of this button)</p></body></html> + <html><head/><body><p>Clear Filter</p></body></html> - :/images/pause_button.png:/images/pause_button.png + :/images/clear_filter_button.png:/images/clear_filter_button.png - + 30 @@ -141,17 +141,20 @@ - <html><head/><body><p>Delete the current capture (not available when capturing or when there is nothing to delete)</p></body></html> + <html><head/><body><p>Stop capturing packets</p></body></html> - :/images/trash_button.png:/images/trash_button.png + :/images/stop_capture_button.png:/images/stop_capture_button.png + + + @@ -288,13 +291,45 @@ + + + true + + + + 16 + 16 + + + + false + + + TopToolBarArea + + + false + + + + + + + + + + + + + + 0 0 605 - 25 + 22 @@ -324,38 +359,6 @@ - - - true - - - - 16 - 16 - - - - false - - - TopToolBarArea - - - false - - - - - - - - - - - - - - @@ -464,6 +467,11 @@ Ctrl+X + + + Choose another device + + diff --git a/packetsnifferthread.cpp b/packetsnifferthread.cpp index f611da0..9d04600 100644 --- a/packetsnifferthread.cpp +++ b/packetsnifferthread.cpp @@ -24,23 +24,24 @@ #include "tags.h" -PacketSnifferThread::PacketSnifferThread(QStandardItemModel *packetModel, QStatusBar *statusBar){ +PacketSnifferThread::PacketSnifferThread(QStandardItemModel *packetModel, QStatusBar *statusBar,std::string device){ this->packetModel = packetModel; this->statusBar = statusBar; stopCapture = false; packetNumber = 0; rawDataView = Binary; captureSaved = false; + devicea = device; } -PacketSnifferThread::PacketSnifferThread(QStandardItemModel *packetModel, QString filePath, QStatusBar *statusBar){ +PacketSnifferThread::PacketSnifferThread(QStandardItemModel *packetModel, QString filePath, QStatusBar *statusBar,std::string device){ this->packetModel = packetModel; this->statusBar = statusBar; stopCapture = false; packetNumber = 0; rawDataView = Binary; captureSaved = false; - + devicea = device; QHash protocolColors; protocolColors.insert("ARP", QColor(255, 125, 125)); //Light Red protocolColors.insert("DNS", QColor(183, 247, 119)); //Light Green @@ -144,8 +145,8 @@ void PacketSnifferThread::run(){ protocolColors.insert("HTTPS", QColor(121, 201, 201)); //Dark Cyan protocolColors.insert("ICMP", QColor(232, 209, 255)); //Light Purple protocolColors.insert("Unknown", QColor(255, 253, 140)); //Light Yellow - - const char *device = ETHERNET_DEVICE; //The device to sniff on + + const char *device = devicea.c_str(); //The device to sniff on pcap_t *handle; //The session handle char errorBuffer[PCAP_ERRBUF_SIZE]; //The buffer to store error messages in bpf_u_int32 networkNumber; //32 bit network address diff --git a/packetsnifferthread.h b/packetsnifferthread.h index ae8eb6e..5b8de5f 100644 --- a/packetsnifferthread.h +++ b/packetsnifferthread.h @@ -2,7 +2,7 @@ #define PACKETSNIFFERTHREAD_H #include - +#include #include #include #include @@ -15,8 +15,8 @@ enum RawDataView { class PacketSnifferThread : public QThread{ public: - PacketSnifferThread(QStandardItemModel *packetModel, QStatusBar *statusBar); - PacketSnifferThread(QStandardItemModel *packetModel, QString filePath, QStatusBar *statusBar); + PacketSnifferThread(QStandardItemModel *packetModel, QStatusBar *statusBar,std::string device); + PacketSnifferThread(QStandardItemModel *packetModel, QString filePath, QStatusBar *statusBar,std::string device); ~PacketSnifferThread(); private: @@ -39,6 +39,7 @@ class PacketSnifferThread : public QThread{ bool saveCapture(QString filePath); void saveCaptureAs(void); void openCapture(void); + std::string devicea= "wlo1"; }; #endif // PACKETSNIFFERTHREAD_H diff --git a/shared.h b/shared.h index 611e9a2..695f514 100644 --- a/shared.h +++ b/shared.h @@ -6,7 +6,7 @@ #include #include -#define ETHERNET_DEVICE "enp0s3" // IMPORTANT: Change this to your ethernet device name in "ifconfig" + //If the character passed to this macro is a printable character, return non-zero #define IS_PRINTABLE(c) (((c) >= 32) && ((c) <= 126))