In a previous post entitled “How to get unlimited free Internet at Airports“, I showed you how to circumvent the time limit imposed by the “free” Wi-Fi connections in certain airports.
For that trick to work, you were required to update the MAC address of your computer each time the free time is over.
In this blog post, I am going to share with you the ChangeMACAddressBatch script that I wrote with the help and instructions from the excellent Batchography book.
The script makes use of various recipes illustrated in the Batchography book (in Chapter 4) and uses the various Batch scripting language syntax (Chapters 1 and 2) and methodologies (Chapter 3). Therefore, I will not be explaining the script’s contents or how it works because it will become evident if you read the Batchography book.
Get the book from Amazon:
How to use the script interactively
To begin with, you need to run the script with administrative privileges.
Running the script as an administrator
On Windows 8 and above, just press Win+X and choose “Command Prompt (Admin)” like this:
Otherwise, if you are using the Windows Explorer window, then right-click on your script and choose “Run as Administrator”:
Starting the script
When you first run the script, you will be presented with the main menu that will show you a list of all the adapters you have on your system.
On my laptop for instance, I have 4 adapters:
- An Ethernet adapter
- 2 x VMWare virtual adapters
- A Wi-Fi adapter
Using the keyboard, type the adapter number that you want to inspect and/or change its MAC address:
Let’s press “4” in this case and go inside that adapter’s information screen.
The network adapter information screen
Once inside the network adapter information screen:
…you will see how the first part of the screen displays the information about the network adapter:
- The adapter’s friendly name
- The adapter’s driver name
- The current MAC address
- The connection status (Connected or Disconnected)
In the second part of the screen, you will be presented with a menu containing three options:
- Change the MAC address: allows you to change the MAC address
- Reset the MAC address
- Or go back to the main menu
Changing the MAC address
Let us press “C” to change the MAC address:
When you press “C”, you will be prompted to enter a new MAC address. A few examples of valid MAC addresses are presented to you.
Note: If you are changing the MAC address of a Wi-Fi adapter then please heed the instructions presented by the script (start the new address with “02” or “06”).
After you enter the new MAC address, you will be taken back to the main screen.
Note: In the case of a Wi-Fi adapter, you may want to reconnect to the Wireless network again (if “Reconnect automatically” was not specified for a given access point).
That’s it!
Resetting the MAC address
If for some reason you want to revert back the MAC address to its original value (the address value embedded in your network adapter), then choose the “R” (to Reset) option from the adapter menu:
Using the script from the command line
The ChangeMACAddressBatch script not only works interactively, it also works as a command-line tool.
First, let us run it with the “help” argument to display its usage information:
Listing the adapters
Use the “list” command line argument to list all the adapters friendly names:
Changing the MAC address
Use the “change” command line argument to change the MAC address of a given adapter name:
Resetting the MAC address
Use the “reset” command line argument to reset the MAC address of a given adapter name:
Downloading the script
You may download the script from the Batchography book‘s source code repository on GitHub:
Note: After you download the script, you may receive a message like the following:
Please do not be concerned about this. Windows will always show such a warning for scripts it does not know about. If you are paranoid, please read the script source code.
After you download the archive, unpack it, retrieve the script and run it from an elevated command prompt (aka as an Administrator user).
How to change the MAC address of an adapter manually?
The idea is to go to the registry key located here (use regedit.exe):
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}]
Therein, you will find a bunch of interface numbers registry sub-keys: “0000”, “0001”, “0002”, etc:
You have to find the proper interface number registry sub-key and then add or edit the desired “NetworkAddress” REG_SZ value like this:
The ChangeMACAddressBatch script automates this whole task and makes it simple.
You might also like:
- Introducing the “Batchography: The Art of Batch Files Programming” book
- WifiPasswordReveal: A script to reveal all the saved WiFi passwords in Windows 7 and above
- Batchography: Building a dynamic menu in Batch files – Part 1
- How to get unlimited free Internet at Airports
- Reference: Stackoverflow – How to change mac address with batch file on windows
- Reference: How to set or get the networkaddress key from the registry
- Reference: MAC Address
@echo off
set file=”%~dp0changemac.txt”
wmic path Win32_NetworkAdapter where “netconnectionstatus=2” get index,macAddress,netconnectionid >%file%
for /F “skip=1 tokens=1,2,*” %%a in (‘type %file%’) do (set index=%%a) & (set macr=%%b) & set nombrewifi=%%c
del %file%
echo Index: “%index%”
if “%index%”==”” goto sale
if %index% lss 10 (set qqq=000%index%) else set qqq=00%index%
set rutareg=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%qqq%
echo “%rutareg%”
for /f “tokens=1-6 delims=: ” %%a in (“%macr%”) do set mac=%%a%%b%%c%%d%%e%%f
echo MACAddress: “%mac%”
if “%mac%”==”” goto sale
echo NetConnectionID_: “%nombrewifi%”
:resta
if “%nombrewifi:~-1%”==” ” (set nombrewifi=%nombrewifi:~0,-1%) & goto resta
echo NetConnectionID: “%nombrewifi%”
if “%nombrewifi%”==”” goto sale
set q=%time:~0,2%
if %q% lss 10 set q=0%q:~1,1%
set resa=D2%date:~0,2%%q%%time:~3,2%%time:~6,2%%time:~9,2%
echo New MACAddress: “%resa%”
goto sale
reg query %rutareg% /v NetworkAddress_original
if errorlevel 1 reg add %rutareg% /v NetworkAddress_original /t REG_SZ /d %mac% /f
reg add %rutareg% /v NetworkAddress /t REG_SZ /d %resa% /f
echo Disable/enable adapter…
netsh interface set interface “%nombrewifi%” disabled
netsh interface set interface “%nombrewifi%” enabled
:sale
pause