不同系统执行ipconfig/all显示不同,想了个办法回避不同格式部分,试试,如不行得在命令行执行前述命令把显示的贴我看
@echo off
for /f "delims=:" %%i in (
'ipconfig/all^|findstr/nrc:"本地连接 *3"')do set/a n=%%i
for /f "tokens=2 delims=:" %%i in (
'ipconfig/all^|more +%n%^|findstr "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]"')do (
if not defined d4 set "d4=%%~xi")
set/a d4=%d4:~1%
echo 所获取值为: "%d4%"
pause
以下代码只做参考
@echo off
for /f "tokens=1 delims=:" %%a in ('ipconfig /all^|findstr /n /c:"本地连接 3"') do (
ipconfig /all|more +%%~a>ip.txt
for /f "tokens=2 delims=:(首选)" %%b in ('findstr /c:"IPv4 地址" "ip.txt"') do (
echo.%%b>ip.txt
for /f "tokens=4 delims=." %%c in (ip.txt) do echo %%c
del ip.txt
)
)
pause