How to change MAC address with batch file on Windows 7? [closed]

情到浓时终转凉″ 提交于 2020-01-01 12:33:06

问题


I want to change with simple click (using a batch file) the MAC address of my wireless device. How I'll accomplish this? It needs to choose a random MAC address.


回答1:


I am not sure if this is completely correct but it would be something like:

In a .reg file

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0009]
"NetworkAddress"="000011112222"

The 0009 would have to change to match the address you your adapter.




回答2:


Run next command from batch file:

reg add HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001 /v NetworkAddress /d 0123456789AB

Replace 0001 with your interface number and 0123456789AB with desired network addres.




回答3:


Here is the definite batch file for changing MAC address on Windows 7: Like the (misleading)title of this question, it's missing the random part (left as an exercise to replace set /p with a call to a generator label). Handy now, with all this Denial-of-service-ing comeback...

:: Change MAC script by bobdynlan, release 1
:: For each network adapter it will list RegPath, GUID, Name, previous modified MAC if exists
:: Then you can input new MAC, clear previous MAC by inputting 0 or skip by pressing [Enter]
:: You can paste directly from ipconfig or wireshark because : < > { } [ ] - ( ) . will be filtered out
:: Note that for wireless in Win7 standard drivers has to start with 02... 06... 0A... 0E...
@ECHO OFF &SET /A RLINE=1 &SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /F "tokens=3*" %%I IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards" /S^|FINDSTR /I /L "REG_SZ"') DO (
SET /A RLINE+=1 &SET /A PARITY=!RLINE!^%%2
IF !PARITY! EQU 0 (SET "ADAPTERGUID=%%I") ELSE (
SET "ADAPTERNAME=%%I %%J"
FOR /F %%A IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}" /F "!ADAPTERGUID!" /D /E /S ^|FINDSTR /I /L /V "Linkage"^|FINDSTR /I /L "\\Class\\"') DO SET "REGPATH=%%A"
CLS &echo       Change MAC script by bobdynlan, release 1 &echo. &echo     RegPath = !REGPATH!  &echo     GUID = !ADAPTERGUID!  &echo     Adapter name = !ADAPTERNAME!
REG QUERY "!REGPATH!" /V "NetworkAddress" 2>&1 |FINDSTR /I /L "NetworkAddress"
SET "CHANGEMAC=" &SET "RESETMAC="
echo. &echo  Enter MAC address for this adapter [0 to reset it] or press [Enter] to skip: &SET /P "CHANGEMAC="
IF "!CHANGEMAC!"=="0" (SET "RESETMAC=Y" &SET "CHANGEMAC=") ELSE SET "RESETMAC="
IF DEFINED CHANGEMAC SET "CHANGEMAC=!CHANGEMAC: =!" &FOR %%I IN (: ^< ^> { } [ ] - ^( ^) .) DO SET "CHANGEMAC=!CHANGEMAC:%%I=!"
IF DEFINED CHANGEMAC REG ADD "!REGPATH!" /F /V NetworkAddress /T REG_SZ /D !CHANGEMAC! >nul 2>&1
IF DEFINED RESETMAC REG DELETE "!REGPATH!" /F /V NetworkAddress >nul 2>&1
))
IF DEFINED CHANGEMAC FOR /F "tokens=2,4*" %%I IN ('netsh interface show interface^|FINDSTR /I /L "Enabled"') DO (
netsh interface set interface %%J DISABLED
netsh interface set interface %%J ENABLED
)

ChangeMAC.bat




回答4:


There is a changeMac.bat file.

@echo off
netsh interface set interface "Local Area Connection" disable
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007 /v NetworkAddress /d 002622D90EFC /f
netsh interface set interface "Local Area Connection" enable
echo Ok, enjoy it :)

There are three place you may need change: Local Area Connection, 0007, 002622D90EFC. Note: you must open regedit to find out what you should change the 0007 argument to. The Mac address has some rules: the second bit must be one of these numbers: 0 2 6 A E.

There is a recoverMac.bat that you may need.

@echo off
netsh interface set interface "Local Area Connection" disable
reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007 /v NetworkAddress /f
netsh interface set interface "Local Area Connection" enable
echo Ok,enjoy it :)



回答5:


you can use Technitium MAC Address changer command line to do it. Only you need to have it installed on the target machine.




回答6:


  1. batch script yourself a cmd line regedit.
  2. Change the registry key value, like link here: http://www.windowsreference.com/networking/how-to-change-mac-address-in-windows-registry/


来源:https://stackoverflow.com/questions/8753043/how-to-change-mac-address-with-batch-file-on-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!