for /f "tokens=16" %%i in ('ipconfig ^|find /i "ipv4"') do set ip=%%i
for /f "tokens=15" %%i in ('ipconfig /all ^| find /i "子网掩码 "') do set mask=%%i
for /f "tokens=15" %%i in ('ipconfig /all ^| find /i "默认网关"') do set gateway=%%i
for /f "tokens=16" %%i in ('ipconfig /all ^| find /i "DNS"') do set dns=%%i
for /f "tokens=16" %%i in ('ipconfig /all ^| find /i "主机名"') do set name=%%i
echo 本机IP为: %ip%
echo 本机子网掩码为:%mask%
echo 本机网关为: %gateway%
echo 本机首选DNS为: %dns%
echo 主机名为: %name%
下面是获取的内容,而且我的地址是192.168.0.60,变成了192.168.56.1
本机IP为: 192.168.56.1
本机子网掩码为:255.255.255.0
本机网关为: 192.168.2.1
本机首选DNS为: fec0:0:0:ffff::1%1
主机名为: KKKK