echo off
set "mac=11-22-33-AA-BB-CC"
setlocal enabledelayedexpansion
echo 正在获取所有连接与MAC对应信息 ...
for /f "tokens=* delims=:" %%a in (
'ipconfig/all^|findstr/i /c:"Ethernet adapter" /c:"Physical Address"')do (
echo %%a
set "q=%%a"
if not "!q:%mac%=!"=="!q!" (
for /f "tokens=2* delims=: " %%b in ('echo;%%#!n!%%')do set eth=%%c)
set "#!n!=%%a")
echo;
if not defined eth (
set/p=未找到指定网卡 %mac% 请按任意键退出... <nul
pause>nul&exit /b)
endlocal&set "eth=%eth::=%"
echo 对应网卡 %mac% :%eth%
pause
或
@echo off
setlocal enabledelayedexpansion
echo 正在获取所有连接与MAC对应信息 ...
for /f "tokens=1* delims=:" %%a in (
'ipconfig/all^|findstr/i /c:"Ethernet adapter" /c:"Physical Address"')do (
set/a "n+=1,m1=n%%2,m2=(n+1)/2"
if !m1!==0 (
set "q=%%b"
set "mac!m2!=!q: =!"
call echo !m2!.%%eth!m2!%%:%%b
) else (
for /f "tokens=2* delims=: " %%c in ("%%a")do (
set "eth!m2!=%%d")
)
)
echo;
pause