1. 如果在命令窗口中测试的话:
for /f "delims=" %i in ('powershell -c "(Get-NetIPConfiguration | ? {$_.IPv4DefaultGateway -ne $null}).IPv4Address.IPAddress 2>$null"') do echo ******** ip = %i ********
2. 如果在bat脚本中, 请将下面内容复制到bat文件, 并执行
@echo off
set ipv4=""
for /f "delims=" %%i in ('powershell -c "(Get-NetIPConfiguration | ? {$_.IPv4DefaultGateway -ne $null}).IPv4Address.IPAddress 2>$null"') do (
set ipv4="%%i"
)
echo ******* ip = %ipv4% *******
pause