Skip to content

Commit 66b5bcf

Browse files
authored
v0.2a
v0.2a - added multi-threading
1 parent e718605 commit 66b5bcf

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

Main.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@
88
#include <random> // std::default_random_engine
99
#include <chrono> // std::chrono::system_clock
1010
#include <fstream> // for file i/o
11-
#include <iomanip>
12-
11+
#include <iomanip> //get time
12+
#include <thread> // multi-threading
13+
/* Public Declarations */
1314
char hex[30];
14-
15+
int num;
16+
int num2;
17+
/* Version 0.2a - Added threading to the functions. */
18+
void pause() {
19+
std::cin.clear();
20+
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
21+
std::string dummy;
22+
std::cout << "Press any key to exit . . .";
23+
std::getline(std::cin, dummy);
24+
exit(0);
25+
}
1526
bool is_int(std::string str) {
1627
for (int i = 0; i < str.length(); i++)
1728
if (isdigit(str[i]) == false)
1829
return false;
1930
return true;
2031
}
21-
void hex_string(char str[], int length)
22-
{
32+
void hex_string(char str[], int length) {
2333
std::array<char,16> hexchr { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
2434
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
2535
shuffle(hexchr.begin(), hexchr.end(), std::default_random_engine(seed));
@@ -30,9 +40,7 @@ void hex_string(char str[], int length)
3040
}
3141
str[length] = 0;
3242
}
33-
34-
int msg1()
35-
{
43+
int msg1() {
3644
int num;
3745
std::string n;
3846
std::cout << "How many MAC Addresses?\n";
@@ -47,8 +55,7 @@ int msg1()
4755
return 0;
4856
}
4957
}
50-
int msg2()
51-
{
58+
int msg2() {
5259
int num;
5360
std::string n2;
5461
std::cout << "\nWould you like to save to mac.txt? (0 = no | 1 = yes)\n";
@@ -64,6 +71,7 @@ int msg2()
6471
}
6572

6673
std::cout << "\nGenerating please wait...\n";
74+
6775
}
6876
void DoGen(int num) {
6977
char hex[30];
@@ -77,6 +85,7 @@ void DoGen(int num) {
7785
hex_string(hex, 12);
7886
std::cout << hex << "\n";
7987
}
88+
pause();
8089
}
8190
void DoGen2(int num, std::string filename) {
8291
char hex[30];
@@ -96,20 +105,9 @@ void DoGen2(int num, std::string filename) {
96105
std::cout << "Saved file to: " + filename + "\n";
97106
exit(0);
98107
}
99-
void pause()
100-
{
101-
std::cin.clear();
102-
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
103-
std::string dummy;
104-
std::cout << "Press any key to exit . . .";
105-
std::getline(std::cin, dummy);
106-
exit(0);
107-
}
108-
int main()
109-
{
110-
int num, num2;
108+
109+
int main() {
111110
std::string n2;
112-
113111
num = msg1();
114112
if (num == 0) {
115113
std::cout << "You entered an invalid option\n";
@@ -119,12 +117,14 @@ int main()
119117
num2 = msg2();
120118
if (num2 == 0) {
121119
std::cout << "[MAC Address List]\n";
122-
DoGen(num);
120+
std::thread threadObj(DoGen, num);
121+
threadObj.join();
123122
}
124123
else {
125-
DoGen2(num, "mac.txt");
124+
std::thread threadObj2(DoGen2, num, "mac.txt");
125+
threadObj2.join();
126+
126127
}
127128
}
128-
//pause();
129129
return 0;
130-
}
130+
}

0 commit comments

Comments
 (0)