-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
130 lines (126 loc) · 3.18 KB
/
Main.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
#include <iostream>
#include <string>
#include <stdlib.h>
#include <ctype.h>
#include <sstream>
#include <array> // std::array
#include <algorithm> // std::shuffle
#include <random> // std::default_random_engine
#include <chrono> // std::chrono::system_clock
#include <fstream> // for file i/o
#include <iomanip> //get time
#include <thread> // multi-threading
/* Public Declarations */
char hex[30];
int num;
int num2;
/* Version 0.2a - Added threading to the functions. */
void pause() {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::string dummy;
std::cout << "Press any key to exit . . .";
std::getline(std::cin, dummy);
exit(0);
}
bool is_int(std::string str) {
for (int i = 0; i < str.length(); i++)
if (isdigit(str[i]) == false)
return false;
return true;
}
void hex_string(char str[], int length) {
std::array<char,16> hexchr { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
shuffle(hexchr.begin(), hexchr.end(), std::default_random_engine(seed));
int i;
for (i = 0;i < length;i++)
{
str[i] = hexchr[rand() % 16];
}
str[length] = 0;
}
int msg1() {
int num;
std::string n;
std::cout << "How many MAC Addresses?\n";
std::cin >> n;
num = std::stoi(n);
if (is_int(n)) {
return num;
}
else {
std::cout << n << " is not a valid number\n";
exit(0);
return 0;
}
}
int msg2() {
int num;
std::string n2;
std::cout << "\nWould you like to save to mac.txt? (0 = no | 1 = yes)\n";
std::cin >> n2;
num = std::stoi(n2);
if (is_int(n2)) {
return num;
}
else {
std::cout << n2 << " is not a valid number\n";
exit(0);
return 0;
}
std::cout << "\nGenerating please wait...\n";
}
void DoGen(int num) {
char hex[30];
if (num == 0)
{
num = 1;
}
srand(time(0));
for (int i = 0;i < num;i++)
{
hex_string(hex, 12);
std::cout << hex << "\n";
}
pause();
}
void DoGen2(int num, std::string filename) {
char hex[30];
if (num == 0)
{
num = 1;
}
srand(time(0));
std::ofstream outfile;
outfile.open(filename);
for (int i = 0;i < num;i++)
{
hex_string(hex, 12);
outfile << hex << "\n";
}
outfile.close();
std::cout << "Saved file to: " + filename + "\n";
exit(0);
}
int main() {
std::string n2;
num = msg1();
if (num == 0) {
std::cout << "You entered an invalid option\n";
}
else {
std::cout << "You entered:" << num;
num2 = msg2();
if (num2 == 0) {
std::cout << "[MAC Address List]\n";
std::thread threadObj(DoGen, num);
threadObj.join();
}
else {
std::thread threadObj2(DoGen2, num, "mac.txt");
threadObj2.join();
}
}
return 0;
}