A reader asked if there was a way to reset the mac-address to the original value after using my script to set a random MAC address. But also if it’s possible to schedule the script to run every XX minutes as the local coffee shop restricts internet access to 15 minutes per custo…ehh sorry, per MAC Address!
Here is a small function to reset the mac-address, by changing it to 00-00-00-00-00-00 windows will use the default hardware MAC Address of your card.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function reset-macaddress ($wifiadapter){ # Write-Output "Wifi AdapterName: $wifiadapter" # Write-Output "SSID: $ssid" # Write-Output "New MAC Address to set: $newmac" $oldmac = (Get-NetAdapter -Name $wifiadapter).MACAddress Write-Output "OLD MAC Address: $oldmac" Get-NetAdapter -Name $wifiadapter | Set-NetAdapter -MACAddress "00-00-00-00-00-00" -Confirm:$false Get-NetAdapter -Name $wifiadapter | Disable-NetAdapter -Confirm:$false Get-NetAdapter -Name $wifiadapter | Enable-NetAdapter -Confirm:$false $currentmac = (Get-NetAdapter -Name $wifiadapter).MACAddress Write-Output "NEW (Original) MACAddress: $currentmac" } |
Regarding the automatic scheduling of the script. There are a couple of different ways to do that with pros and cons. It’s for example possible to start the script with Windows Task Scheduler ever X minute or let it automatically run, sleep for XX minutes and then execute again, over and over again until you stop it.
It’s even possible to have Windows Task Scheduler monitor the Event log for new Wifi Connections and if there is a connection to the Coffee House WiFi network, then start the script.
But for now, I’ve just added a very basic Loop, which you can add to the script and execute. It will generate a new random MAC Address every 13 minute (13*60 = 780 seconds) and do that 4 times before you have to restart it or you can just adjust the numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$Coffee = 0 Do { $ssid = (& netsh wlan show interfaces | Select-String ' SSID ' | Foreach-Object {$_.ToString()}).replace(" SSID : ","$null") $wifiadapter = (Get-NetAdapter | where Status -EQ "Up" | where MediaType -EQ "802.3" | where MacAddress -EQ (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.IpEnabled -eq $true -and $_.DhcpEnabled -eq $true} | select *).MACAddress.replace(":","-")).Name $newmac = random-mac disconnect-wifi new-wifimac -wifiadapter $wifiadapter -ssid $ssid -newmac $newmac test-wifi -probe www.msftncsi.com Write-Host "Waiting 13 minutes" sleep -Seconds 780 # Set the interval at how often the script should run. $Coffee += 1 } While ($Coffee -lt 5) # Increase this number to have to script run more times. |