forked from RoeeWork/RobustServerController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlWorker.cpp
More file actions
63 lines (58 loc) · 1.91 KB
/
Copy pathControlWorker.cpp
File metadata and controls
63 lines (58 loc) · 1.91 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
#include "Commands.h"
ControlWorker::ControlWorker() {}
void ControlWorker::Start() {
verbose_print("[ControlWorker::Start()] starting ControlWorker::Start()...", verbose);
verbose_print("[ControlWorker::Start()] starting arp-scan", verbose);
std::vector<std::string> arpOut;
try {
arpOut = arpScanOutput();
}
catch (std::exception &e) {
std::cerr << "[ControlWorker::Start()] ERROR running arp-scan: " << e.what() << "\n";
return;
}
verbose_print("[ControlWorker::Start()] done!", verbose);
for (auto &h : this->chosenHosts) {
host_output currHost;
currHost.name = h.name;
currHost.MAC = h.MAC;
try {
bool status = checkStatus(currHost.MAC, arpOut, currHost.IPv4);
status ? currHost.status = "online" : currHost.status = "offline";
}
catch (std::exception &e){
currHost.status = "error";
currHost.IPv4 = "N/A";
std::cerr << "[ControlWorker::Start()] ERROR checking host " << currHost.MAC
<< ": " << e.what() << "\n";
}
this->hostOutputs.push_back(currHost);
}
PrintOutput();
verbose_print("[ControlWorker::Start()] finished!", verbose);
}
void ControlWorker::PrintOutput() {
verbose_print("[ControlWorker::PrintOutput()] starting ControlWorker::PrintOutput()...", verbose);
verbose_print("[ControlWorker::PrintOutput()] printing output...", verbose);
std::cout << "\n";
std::cout << BOLD
<< std::left
<< std::setw(10) << "STATUS"
<< std::setw(20) << "NAME"
<< std::setw(15) << "IPV4"
<< std::setw(20) << "MAC"
<< RESET
<< '\n';
for (auto &h : this->hostOutputs) {
std::string color = (h.status == "online") ? GREEN : RED;
std::cout << BLUE
<< std::left
<< color << std::setw(10) << h.status << RESET
<< std::setw(20) << h.name
<< std::setw(15) << h.IPv4
<< std::setw(20) << h.MAC << RESET
<< '\n';
}
std::cout << "\n";
verbose_print("[ControlWorker::PrintOutput()] done!", verbose);
}