根据这个帖子:http://bbs.bathome.net/viewthread.php?tid=32287&highlight=MAC
为了xp和win7系统都能获取到IP和MAC地址,修改的代码:
@echo off
set "wkmza=Ethernet adapter 本地连接"
set "wkmzb=以太网适配器 本地连接"
set "FileTmp=%temp%\ipList.txt"
ipconfig /all >"%FileTmp%"
for /f "delims=:" %%i in ('findstr /n "%wkmza% %wkmzb%" "%FileTmp%"') do (
set "SkipRow=%%i"
goto oSkip
)
:DoSkip
for /f "tokens=2 delims=:" %%i in ('more +%SkipRow% "%FileTmp%" ^| findstr /i /r "IPv4.地址 IP.Address"') do (set "IP=%%i")
for /f "tokens=2 delims=:" %%i in ('more +%SkipRow% "%FileTmp%" ^| findstr "..-..-..-..-..-.."') do (
set "MAC=%%i"
goto :ShowResult
)
:ShowResult
set "MAC=%MAC: =%"
set "IP=%IP: =%"
echo,IP地址:%IP首选)=%
echo,MAC地址:%MAC:-=%
pause
获取结果:
IP地址:192.168.164.1
MAC地址:4439C4526847
正确的结果IP地址应该是192.168.0.16
标红的代码改成for /f "delims=:" %%i in ('findstr /n /c:"%wkmzb%" "%FileTmp%"') do (
也是一样的结果
这是为什么会得出这样错误的结果?