- @echo off
- setlocal EnableDelayedExpansion
- for /f "tokens=2 delims==" %%i in ('Wmic Nic Where "NetConnectionID<>Null And PNPDeviceID Like '[PR]%%'" Get MACAddress /Value^|find "="') do (
- set /a Sum+=1
- for /f "tokens=2 delims={,}" %%j in ('Wmic NicConfig Where "IPEnabled=True And MACAddress='%%i'" Get IPAddress /Value 2^>nul^|find "="') do (
- set IP!Sum!=%%~j
- set MAC!Sum!=%%i
- )
- )
- for /l %%i in (1,1,%Sum%) do echo;!MAC%%i! !IP%%i!
- pause
复制代码 改成 for /l %%i in (1,1,%Sum%) do echo;!IP%%i! !MAC%%i! 就正常显示了,这是什么原因?
通过楼下的回答,使用变量截取倒数几位可以证实获取到的MACAddress确实存在其他不可见的字符,原因找到就好办了- @echo off
- setlocal EnableDelayedExpansion
- for /f "tokens=2 delims==" %%i in ('Wmic Nic Where "NetConnectionID<>Null And PNPDeviceID Like '[PR]%%'" Get MACAddress /Value^|find "="') do (
- set /a Sum+=1
- set MAC=%%i
- set MAC=!MAC::=-!
- for /f "tokens=2 delims={,}" %%j in ('Wmic NicConfig Where "IPEnabled=True And MACAddress='%%i'" Get IPAddress /Value 2^>nul^|find "="') do (
- set IP!Sum!=%%~j
- set MAC!Sum!=!MAC:~,17!
- )
- )
- for /l %%i in (1,1,%Sum%) do echo;!MAC%%i! !IP%%i!
- pause
复制代码
|