@echo off
mode con cols=70 lines=20
title MAC随机修改工具
color 3F
setlocal enabledelayedexpansion
:start
cls
echo MAC随机修改工具
echo ----------------------------------------------------
echo 本地网卡:
ipconfig /all|find "Description">%temp%\des.txt
devcon find pci\*>%temp%\pci.txt
call :getPCI 1
call :getMAC 1
echo !pci!
echo Physical Address:%MAC%
echo ----------------------------------------------------
if "1"=="1" (
call :setMAC
call :getPCI 2
echo MAC随机修改成功
goto end
pause
)
goto start
:setMAC
if not exist MAC.txt (
echo 没有找到存储MAC的文件MAC.txt,请在该程序目录下建立
echo MAC.txt并存储MAC地址,每一个地址占一行!!!
pause>nul
goto start
)
set /a var=0
for /f %%i in (MAC.txt) do set /a var=!var!+1
set /a var=!random!%%!var!+1
set /a tmp=0
for /f "tokens=1,2 delims= " %%i in (MAC.txt) do (
set /a tmp=!tmp!+1
if !tmp!==!var! (
set MAC=%%i
echo %%i %%j
pause
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001" /v NetworkAddress /d %%i /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /v NetworkAddress /d %%i /f
netsh interface ip delete dns "本地连接" addr=all
netsh interface ip add dns "本地连接" addr=192.168.116.2
netsh interface ip add address "本地连接" 192.168.116.%%j 255.255.255.0
netsh interface ip add address "本地连接" gateway=192.168.116.2 gwmetric=2
goto :eof
)
)
goto :eof
:getPCI
for /f "tokens=2 delims=:" %%i in (%temp%\des.txt) do (
for /f "tokens=2 delims=&" %%j in (\'type "%temp%\pci.txt"^|find "%%i"\') do (
if %1==1 (
set pci=%%i
set pci=!pci:~1,-1!
goto :eof
)
if %1==2 (
echo 正在禁用网卡...
devcon disable *%%j*>nul
echo 正在启用网卡...
devcon enable *%%j*>nul
)
)
)
goto :eof
:end
if exist %temp%\des.txt del %temp%\des.txt
if exist %temp%\pci.txt del %temp%\pci.txt