如何在 Windows 7 上使用批处理文件更改 MAC 地址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8753043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change MAC address with batch file on Windows 7?
提问by ilhan
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.
我想通过简单的点击(使用批处理文件)更改我的无线设备的 MAC 地址。我将如何实现这一点?它需要选择一个随机的 MAC 地址。
采纳答案by Axis
I am not sure if this is completely correct but it would be something like:
我不确定这是否完全正确,但它会是这样的:
In a .reg file
在 .reg 文件中
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}reg add HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}@echo off
netsh interface set interface "Local Area Connection" disable
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}@echo off
netsh interface set interface "Local Area Connection" disable
reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}:: 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
)
07 /v NetworkAddress /f
netsh interface set interface "Local Area Connection" enable
echo Ok,enjoy it :)
07 /v NetworkAddress /d 002622D90EFC /f
netsh interface set interface "Local Area Connection" enable
echo Ok, enjoy it :)
01 /v NetworkAddress /d 0123456789AB
09]
"NetworkAddress"="000011112222"
The 0009 would have to change to match the address you your adapter.
0009 必须更改以匹配您的适配器地址。
回答by Matej
Run next command from batch file:
从批处理文件运行下一个命令:
##代码##Replace 0001
with your interface number and 0123456789AB
with desired network addres.
替换0001
为您的接口号和0123456789AB
所需的网络地址。
回答by Xiaorong Liao
There is a changeMac.bat file.
有一个 changeMac.bat 文件。
##代码##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.
您可能需要更改三个地方:Local Area Connection
, 0007
, 002622D90EFC
。
注意:您必须打开 regedit 以找出您应该将0007
参数更改为什么。Mac 地址有一些规则:第二位必须是以下数字之一:0 2 6 A E。
There is a recoverMac.bat that you may need.
您可能需要一个recoverMac.bat。
##代码##回答by AveYo
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 /pwith a call to a generator label). Handy now, with all this Denial-of-service-ing comeback...
这是用于在 Windows 7 上更改 MAC 地址的明确批处理文件:与此问题的(误导性)标题一样,它缺少随机部分(作为练习,将set /p替换为对生成器标签的调用)。现在方便了,所有这些拒绝服务的回归......
##代码##回答by MrFilter
you can use Technitium MAC Addresschanger command line to do it. Only you need to have it installed on the target machine.
您可以使用Technitium MAC Addresschanger 命令行来执行此操作。只有您需要将它安装在目标机器上。
回答by Ryan
- batch script yourself a cmd line regedit.
- Change the registry key value, like link here: http://www.windowsreference.com/networking/how-to-change-mac-address-in-windows-registry/
- 批处理脚本自己一个 cmd 行 regedit。
- 更改注册表项值,例如此处的链接:http: //www.windowsreference.com/networking/how-to-change-mac-address-in-windows-registry/