8
8
#include < random> // std::default_random_engine
9
9
#include < chrono> // std::chrono::system_clock
10
10
#include < fstream> // for file i/o
11
- #include < iomanip>
12
-
11
+ #include < iomanip> // get time
12
+ #include < thread> // multi-threading
13
+ /* Public Declarations */
13
14
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
+ }
15
26
bool is_int (std::string str) {
16
27
for (int i = 0 ; i < str.length (); i++)
17
28
if (isdigit (str[i]) == false )
18
29
return false ;
19
30
return true ;
20
31
}
21
- void hex_string (char str[], int length)
22
- {
32
+ void hex_string (char str[], int length) {
23
33
std::array<char ,16 > hexchr { ' 0' ,' 1' ,' 2' ,' 3' ,' 4' ,' 5' ,' 6' ,' 7' ,' 8' ,' 9' ,' A' ,' B' ,' C' ,' D' ,' E' ,' F' };
24
34
unsigned seed = std::chrono::system_clock::now ().time_since_epoch ().count ();
25
35
shuffle (hexchr.begin (), hexchr.end (), std::default_random_engine (seed));
@@ -30,9 +40,7 @@ void hex_string(char str[], int length)
30
40
}
31
41
str[length] = 0 ;
32
42
}
33
-
34
- int msg1 ()
35
- {
43
+ int msg1 () {
36
44
int num;
37
45
std::string n;
38
46
std::cout << " How many MAC Addresses?\n " ;
@@ -47,8 +55,7 @@ int msg1()
47
55
return 0 ;
48
56
}
49
57
}
50
- int msg2 ()
51
- {
58
+ int msg2 () {
52
59
int num;
53
60
std::string n2;
54
61
std::cout << " \n Would you like to save to mac.txt? (0 = no | 1 = yes)\n " ;
@@ -64,6 +71,7 @@ int msg2()
64
71
}
65
72
66
73
std::cout << " \n Generating please wait...\n " ;
74
+
67
75
}
68
76
void DoGen (int num) {
69
77
char hex[30 ];
@@ -77,6 +85,7 @@ void DoGen(int num) {
77
85
hex_string (hex, 12 );
78
86
std::cout << hex << " \n " ;
79
87
}
88
+ pause ();
80
89
}
81
90
void DoGen2 (int num, std::string filename) {
82
91
char hex[30 ];
@@ -96,20 +105,9 @@ void DoGen2(int num, std::string filename) {
96
105
std::cout << " Saved file to: " + filename + " \n " ;
97
106
exit (0 );
98
107
}
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 () {
111
110
std::string n2;
112
-
113
111
num = msg1 ();
114
112
if (num == 0 ) {
115
113
std::cout << " You entered an invalid option\n " ;
@@ -119,12 +117,14 @@ int main()
119
117
num2 = msg2 ();
120
118
if (num2 == 0 ) {
121
119
std::cout << " [MAC Address List]\n " ;
122
- DoGen (num);
120
+ std::thread threadObj (DoGen, num);
121
+ threadObj.join ();
123
122
}
124
123
else {
125
- DoGen2 (num, " mac.txt" );
124
+ std::thread threadObj2 (DoGen2, num, " mac.txt" );
125
+ threadObj2.join ();
126
+
126
127
}
127
128
}
128
- // pause();
129
129
return 0 ;
130
- }
130
+ }
0 commit comments