-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from alyosama/string_matching
String matching
- Loading branch information
Showing
13 changed files
with
938 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "statistics.h" | ||
|
||
statistics::statistics() | ||
{ | ||
|
||
ipConverter["213.158.163.117"]="Google"; | ||
ipConverter["93.184.220.127"]="soundcloud"; | ||
ipConverter["96.17.211.172"]="cambridge"; | ||
map2["Google"]=0; | ||
map2["soundcloud"]=0; | ||
map2["cambridge"]=0; | ||
} | ||
|
||
void statistics::check(RawPacket * r){ | ||
|
||
Packet packet(r); | ||
if (packet.isPacketOfType(IPv4)) | ||
{ | ||
IPv4Layer* ipv4layer= packet.getLayerOfType<IPv4Layer>(); | ||
|
||
total++; | ||
if( ipConverter.find(ipv4layer->getDstIpAddress().toString()) != ipConverter.end()) | ||
{ | ||
this->mycount(ipConverter[ipv4layer->getDstIpAddress().toString()]); | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
int statistics::mycount(string y) | ||
{ | ||
return ++map2[y]; | ||
} | ||
|
||
void statistics::print() | ||
{ | ||
map<string, int>::iterator it = map2.begin(); | ||
map<string, int>::iterator it1 = map2.end(); | ||
|
||
for(;it!=it1;it++) | ||
cout<< it->first << " "<< it->second <<endl; | ||
|
||
cout<<"total: "<< total<<endl; | ||
} | ||
|
||
void statistics::openStatisticsDialog() | ||
{ | ||
statDialog = new statisticsDialog(); | ||
map<string, int>::iterator it = map2.begin(); | ||
map<string, int>::iterator it1 = map2.end(); | ||
|
||
for(;it!=it1;it++) | ||
statDialog->addItem(it->first, it->second, (1.0*it->second/total) *100); | ||
statDialog->show(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef STATISTICS_H | ||
#define STATISTICS_H | ||
#include<map> | ||
#include <Packet.h> | ||
#include <RawPacket.h> | ||
#include <IPv4Layer.h> | ||
#include <iostream> | ||
#include "statisticsdialog.h" | ||
|
||
using namespace std; | ||
class statistics | ||
{ | ||
public: | ||
statistics(); | ||
map<string,string> ipConverter; | ||
map<string,int> map2; | ||
int total=0; | ||
statisticsDialog *statDialog; | ||
|
||
void check(RawPacket * r); | ||
int mycount(string x); | ||
void openStatisticsDialog(); | ||
|
||
|
||
void print(); | ||
|
||
}; | ||
|
||
#endif // STATISTICS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "statisticsdialog.h" | ||
#include "ui_statisticsdialog.h" | ||
|
||
statisticsDialog::statisticsDialog(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::statisticsDialog) | ||
{ | ||
ui->setupUi(this); | ||
ui->tableWidget->setColumnCount(3); | ||
QStringList m_TableHeader; | ||
m_TableHeader<<"Domain Name"<<"Number of Packets"<<"%"; | ||
ui->tableWidget->setHorizontalHeaderLabels(m_TableHeader); | ||
ui->tableWidget->verticalHeader()->setVisible(false); | ||
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); | ||
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); | ||
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); | ||
} | ||
|
||
statisticsDialog::~statisticsDialog() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void statisticsDialog::addItem(string domainName, int n, float perc) | ||
{ | ||
int rowc = ui->tableWidget->rowCount(); | ||
ui->tableWidget->insertRow(rowc); | ||
ui->tableWidget->setItem(rowc,0,new QTableWidgetItem(QString::fromStdString(domainName))); | ||
ui->tableWidget->setItem(rowc,1,new QTableWidgetItem(QString::number(n))); | ||
ui->tableWidget->setItem(rowc,2,new QTableWidgetItem(QString::number(perc))); | ||
} | ||
|
||
void statisticsDialog::on_pushButton_clicked() | ||
{ | ||
this->~statisticsDialog(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef STATISTICSDIALOG_H | ||
#define STATISTICSDIALOG_H | ||
|
||
#include <QDialog> | ||
#include <string> | ||
using namespace std; | ||
|
||
namespace Ui { | ||
class statisticsDialog; | ||
} | ||
|
||
class statisticsDialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit statisticsDialog(QWidget *parent = 0); | ||
~statisticsDialog(); | ||
void addItem(string domainName, int n, float perc); | ||
|
||
private slots: | ||
void on_pushButton_clicked(); | ||
|
||
private: | ||
Ui::statisticsDialog *ui; | ||
}; | ||
|
||
#endif // STATISTICSDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>statisticsDialog</class> | ||
<widget class="QDialog" name="statisticsDialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>300</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Statistics</string> | ||
</property> | ||
<widget class="QPushButton" name="pushButton"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>150</x> | ||
<y>250</y> | ||
<width>85</width> | ||
<height>27</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>OK</string> | ||
</property> | ||
</widget> | ||
<widget class="QTableWidget" name="tableWidget"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>30</x> | ||
<y>40</y> | ||
<width>311</width> | ||
<height>192</height> | ||
</rect> | ||
</property> | ||
<property name="columnCount"> | ||
<number>3</number> | ||
</property> | ||
<column/> | ||
<column/> | ||
<column/> | ||
</widget> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
Oops, something went wrong.