I am trying to make an executable that will randomize MAC addresses. I have been stuck on making the correct format with the colons.
I want it to be like this XX:XX:XX but I can only get it with the first two pairs. Any feedback is appreciated. Thanks!
#include <iostream>
#include <iomanip>
#include <random>
#include <chrono>
int main()
{
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine generator(seed);
std::uniform_int_distribution<int> distribution(0, 255);
constexprint N = 6;
std::cout << std::setfill('0') << std::uppercase;
for ( int i=0; i < N; ++i ) {
if ( i ) std::cout << ':';
std::cout << std::setw(2) << std::hex << distribution(generator);
}
std::cout << '\n';
return 0;
}
However, real MAC's are not entirely random; some bits indicate whether the MAC is
unicast or multicast, local or globally unique, and first half usually reveals the vendor too.
There are both Python and Perl programs that take those details into account.