-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
127 lines (104 loc) · 3.04 KB
/
main.cpp
File metadata and controls
127 lines (104 loc) · 3.04 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdlib>
bool check_num(char in) {
if (in == '0' || in == '1') {
return true;
}
if (in == '2' || in == '3') {
return true;
}
if (in == '4' || in == '5') {
return true;
}
if (in == '6' || in == '7') {
return true;
}
if (in == '8' || in == '9') {
return true;
}
return false;
}
std::string get_ping(char ping_in[]) {
std::string fixed;
while(!check_num(*ping_in)) {
++ping_in;
}
while(check_num(*ping_in)) {
fixed += *ping_in;
++ping_in;
}
return fixed;
}
int main(int argc, char * argv[]) {
std::string init; //pinging ip, just for info
std::string trash;
int fail = 0; //time out/unreachable
int slow = 0; //time > 120
int pass = 0; //time < 120 && time > 0
char ping[11];
std::ifstream InFile("output.txt");
InFile >> trash >> init;
InFile >> trash >> trash >> trash >> trash >> trash;
for(int i = 0; i < 100; ++i) {
InFile >> trash;
if(!strcmp(trash.c_str(), "Request")) {
++fail;
InFile >> trash >> trash;
}
else {
InFile >> trash >> trash >> trash;
if (!strcmp(trash.c_str(), "Destination")) {
++fail;
InFile >> trash >> trash;
}
else {
InFile >> ping;
std::string ping_num = get_ping(ping);
int fin_ping = atoi(ping_num.c_str());
if(fin_ping > 120) {
++slow;
InFile >> trash;
}
else if(fin_ping <= 120) {
++pass;
InFile >> trash;
}
else {
return 1;
}
}
}
}
for(int i = 0; i < 24; ++i) {
InFile >> trash;
}
char stats[6];
InFile >> stats;
std::string stats_min = get_ping(stats);
int min = atoi(stats_min.c_str());
InFile >> trash >> trash;
InFile >> stats;
std::string stats_max = get_ping(stats);
int max = atoi(stats_max.c_str());
InFile >> trash >> trash;
InFile >> stats;
std::string stats_avg = get_ping(stats);
int avg = atoi(stats_avg.c_str());
std::cout << "Pinged IP: " << init << std::endl;
std::cout << "Num Pass: " << pass << std::endl;
std::cout << "Num Slow: " << slow << std::endl;
std::cout << "Num Fail: " << fail << std::endl;
if(fail == 0) {
std::cout << "% Failed: 0%" << std::endl;
}
else {
std::cout << "% Failed: " << double((fail/double(pass + slow + fail)))*100 << "%" <<std::endl;
}
std::cout << "Min Ping: " << min << std::endl;
std::cout << "Max Ping: " << max << std::endl;
std::cout << "Avg Ping: " << avg << std::endl;
return 0;
}