Mac Address changer (source code)
by BlackVortex1 - 26-12-25, 10:10 AM
#1
source code is below:


#include <windows.h>
#include <iostream>
#include <string>
#include <random>
#include <cstdlib>

std::string generateRandomMAC() {
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(0, 255);

    char mac[13];
    sprintf_s(mac, "%02X%02X%02X%02X%02X%02X",
        0x02,              // Locally administered, unicast
        dis(gen),
        dis(gen),
        dis(gen),
        dis(gen),
        dis(gen));

    return std::string(mac);
}

int run(const std::string& cmd) {
    std::cout << "
[*]" << cmd << std::endl;
    return system(cmd.c_str());
}

int main() {
    std::string adapterName = "Wi-Fi";  // This is correct for most systems
    std::string newMac = generateRandomMAC();

    //CORRECT registry path for your MediaTek MT7902
    std::string registryPath =
        "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Class\\"
        "{4d36e972-e325-11ce-bfc1-08002be10318}\\0002";

    std::cout << "[+] New MAC address: " << newMac << std::endl;

    // 1. Disable Wi-Fi
    run("netsh interface set interface \"" + adapterName + "\" admin=disable");
    Sleep(2000);

    // 2. Apply MAC address
    run("reg add \"" + registryPath +
        "\" /v NetworkAddress /t REG_SZ /d " +
        newMac + " /f");
    Sleep(2000);

    // 3. Re-enable Wi-Fi
    run("netsh interface set interface \"" + adapterName + "\" admin=enable");

    std::cout << "[+] MAC address successfully changed.\n";
    std::cout << "[!] Change is driver-level and may reset on reboot.\n";

    return 0;
}







[*]how to use it step by step is below: 


[*]Compile using Visual Studio (easiest)
  1. Install Visual Studio Community 
    (choose the “Desktop development with C++” workload)
  2. Open Visual Studio →
    Create a new project → Console App → C++
  3. Replace the auto‑generated code with your program.
  4. Build it:
    Build → Build Solution
  5. Run it as Administrator:
    • Right‑click the EXE in
      Code:
      bin/Debug
      or
      Code:
      bin/Release
    • Choose Run as administrator
This is required because:
  • You’re editing HKLM registry keys
  • You’re disabling/enabling network interfaces






[*]2. How to use the program
Once compiled:
  1. Make sure you updated:
    • The correct adapter name
    • The correct registry instance (0000, 0001, 0002, etc.)
  2. Run the EXE as Administrator.
  3. The program will:
    • Generate a random MAC
    • Disable Wi‑Fi
    • Write the registry override
    • Re‑enable Wi‑Fi
  4. You can verify the MAC change with:
Code

Code:
getmac /v








[*]Command to delete the MAC override key
Replace
Code:
000X
with your actual adapter instance (0000, 0001, 0002, etc.):
Code

Code:
reg delete "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\000X" /v NetworkAddress /f
Example (if your adapter is in
Code:
0002
):
Code

Code:
reg delete "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0002" /v NetworkAddress /f

After deleting the key, reload the adapter
You must disable and re-enable the interface so the driver reloads:
Code

Code:
netsh interface set interface "Wi-Fi" admin=disable
netsh interface set interface "Wi-Fi" admin=enable
Reply


Forum Jump:


 Users browsing this thread: 2 Guest(s)