-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconverter.cpp
152 lines (134 loc) · 4.61 KB
/
converter.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Network File Converter
Authour:Sharma Harsh
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License with
this document.
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.*/
//Please Edit the file so as to find the required feature from the Log
#include<regex>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
const regex hostname("[a-zA-Z0-9_-]+.pune.cdac.in");
const regex typepattern("type=[a-zA-Z0-9_-]+");
const regex subtypep("subtype=[a-zA-Z0-9_-]+");
const regex eventtypep("eventtype=[a-zA-Z0-9_-]+");
const regex srcipp("srcip=[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}");
const regex dstipp("dstip=[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}");
const regex dstportp("dstport=[0-9]+");
const regex statusp("status=[a-zA-Z\"]+");
/*const regex srcportp("srcport=[0-9]+");
const regex datep("date=[0-9]{4}[-/][0-9]{2}[-/][0-9]{2}");
const regex timep("time=[0-9]{2}:[0-9]{2}:[0-9]{2}");
const regex levelp("level=[0-9a-zA-Z_-]+");
const regex attacknamep("attackname=\".*?\"");
const regex srcintfp("srcintf=\"[0-9a-zA-Z_-]+\"");
const regex dstintfp("dstintf=\"[0-9a-zA-Z_-]+\"");
sessionidp=re.compile(r'sessionid=\d{1,10}');
const regex policyidp("policyid=[0-9]+");
const regex dstcountryp("dstcountry=\"[a-zA-Z0-9\s]+\""); #include white spaces w~[a-zA-Z0-9]so [ \w]+ works
srccountryp=re.compile(r'srccountry="[ \w]+"')
trandispp=re.compile(r'trandisp=\w+')
servicep=re.compile(r'service=[/\w-]+')
srcnamep=re.compile(r'srcname=[\w-]+')
durationp=re.compile(r'duration=\d+')
sentbytep=re.compile(r'sentbyte=\d+')
rcvdbytep=re.compile(r'rcvdbyte=\d+')
devtypep=re.compile(r'devtype="[ \w]+"')
osnamep=re.compile(r'osname="[ \w]+"')
osversionp=re.compile(r'osversion="[\w ]+"')
mastersrcmacp=re.compile(r'mastersrcmac=\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2}')
srcmacp=re.compile(r'srcmac=\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2}')
crscorep=re.compile(r'crscore=\d+')
cractionp=re.compile(r'craction=\d+')
unauthusersourcep=re.compile(r'unauthusersource="\w+"')
unauthuserp=re.compile(r'unauthuser="[ \[email protected]]+"')
vdp=re.compile(r'vd=[\w"]+')
vpntunnelp=re.compile(r'vpntunnel="\w+"')
protop=re.compile(r'proto=\d+')
sentpktp=re.compile(r'sentpkt=\d')
rcvdpktp=re.compile(r'rcvdpkt=\d+')
transipp=re.compile(r'transip=\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}')
transportp=re.compile(r'transport=\d+')
msgp=re.compile(r'msg="[ \w.:,]+"')
const regex rolep("role=[a-zA-A0-9]+");
const regex appp("app=[\"a-zA-Z0-9-]+");
const regex applistp("applist=\"[a-zA-Z0-9-]+\"");
*/
const regex equality("[a-zA-Z0-9_-]+=");
int regex_searching(string s,vector<regex> r);
int main(int argc, char *argv[])
{
int i=0;
vector<regex> regvec; //Pushing regex into a vector as working with vectors is faster and more efficient than remembering individual regex names
smatch temp;
ofstream outfile;
outfile.open("./heatmaptry1.csv",ios::out);
//regvec.push_back(hostname);
regvec.push_back(srcipp);
regvec.push_back(dstipp);
regvec.push_back(dstportp);
regvec.push_back(statusp);
//regvec.push_back(typepattern);
//regvec.push_back(subtypep);
//regvec.push_back(eventtypep);
//ofstream outfile("./converted.csv");
while(++i<argc)
{
ifstream infile;
infile.open(argv[i]);
//outfile.open("./heatmaptry"+to_string(i-1)+".csv",ios::out);
cout<<i<<". opening "<<argv[i];
if(outfile.is_open())
{
if(infile.is_open())
{
for(string line;getline(infile,line);)
{
outfile<<(line.substr(0,32))<<","; //writing the time stamp composed of first 32 charecters
for(int i=0;i<regvec.size();i++)
{
if(!regex_match(line,regvec[i]))
{
regex_search(line,temp,regvec[i]);
outfile<<regex_replace(temp.str(),equality,"")<<",";
}
else
outfile<<",";
}
outfile<<"\n";
}
cout<<" Done!"<<endl;
infile.close();
}
else
{
cout<<"Error opening file "<<argv[i];
exit(1);
}
}
else
{
cout<<"unable to write to file";
exit(1);
}
//outfile.close();
}
outfile.close();
cout<<"completed";
return 0;
}