2

I recently learned how to change my MAC address thanks to https://superuser.com/questions/1514745/how-to-change-mac-address-on-windows-10-without-third-party-software/1544773 but I was wondering if I could implement this in a batch file. The registry key for my NIC is HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0011. I want to create a batch file that randomizes my MAC Address. You don't need to create the batch file for me (you can, I can't control you), but pointers would be really appreciated.

Thanks in advance,

Asian

1 Answers1

1

Here is my code, I've done this before.

@echo off
dism >nul
if %errorlevel% NEQ 0 goto Elevate
(call )
netsh interface set interface Wi-Fi disable
timeout /t 1 /nobreak >null
netsh interface set interface Wi-Fi enable
choice /c RC /m "Would you like to randomize your MAC adress or customize it?"
if %Errorlevel% EQU 2 goto custom
set loopcount=5
:loop
set /a loopcount=loopcount-1
if %loopcount% LEQ 0 (goto exitloop)
set /a "ascii = %random% * 26 / 32768 + 65"
cmd /c exit /b %ascii%
set "rl1=%rl1%%=ExitCodeAscii%
goto loop
:exitloop
set MAC="0E%random:~0,2%%rl1:~0,2%%random:~0,2%%rl1:~3,2%%rl1:~-1%%random:~0,1%"
goto after
:custom
echo What would you like to change your MAC address to?
echo Remember to always have the second digit of your MAC address to always be a 2, 6, A, or E
echo Format: AABBCCDDEEFF
echo/
set /p MAC="Input your MAC address here (no spaces or hyphens)> "
:after
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0011" /v NetworkAddress /d %MAC% /f >null
netsh interface set interface Wi-Fi disable
timeout /t 1 /nobreak >null
netsh interface set interface Wi-Fi enable
echo Operation Successful
echo %mac% is your new MAC address
pause
goto :eof
:Elevate
Echo Error: The requested operation requires elevation
Echo Run file again as admin
Echo Closing file in 10 seconds...
timeout /t 10 /nobreak >nul
goto :eof

It sometimes requires a restart before doing it to work but it usually works fine.

Nico Nekoru
  • 2,402
  • 1
  • 15
  • 32
  • One hint: There should be never used `ControlSet001`. It is not guaranteed that it exists at all. It should be always used `CurrentControlSet`. Which control set is the current control set and which one is the last known good control set is defined by the double word values in Windows registry under key `HKEY_LOCAL_MACHINE\SYSTEM\Select`. I have one Windows PC on which `ControlSet001` does not exist anymore and `ControlSet003` is `CurrentControlSet`. – Mofi Apr 24 '20 at 07:49
  • Yes indeed, it just depends on how Windows was downloaded on the machine and if it was reinstalled. However, in the question, Asian said that his NIC registry path did in fact have ControlSet001 which is why I put it there – Nico Nekoru Apr 24 '20 at 16:38
  • Your code provide on my machine invalid randomized MACs `0E26HZ66RBZ1` or `0E12BZ32JJ8`. Just copy&paste your code, what am I doing wrong? – user2956477 Sep 27 '21 at 16:55
  • @user2956477 https://stackoverflow.com/q/61862248/12671858 I didn't realize that Mac addresses were hex when I made this code, this was resolved in this post – Nico Nekoru Sep 28 '21 at 22:07
  • Nevermind, I found this code in the meantime https://www.dostips.com/forum/viewtopic.php?t=4833 – user2956477 Sep 29 '21 at 05:36