- @echo off
- setlocal enabledelayedexpansion
-
- set command=" ipconfig /all | findstr /c:"IP Address" /c:"Subnet Mask" /rc:"Gateway.*[0-9].*" /c:"DNS Servers" /rc:"[ ][ ][ ]*[0-9]" "
-
- for /f "tokens=1,2,*" %%a in (' %command% ') do (
- if "%%b"=="" (
- set DNS_Servers2=%%a
- ) else (
- set value=%%c
- set value=!value:*:=!
- set %%a_%%~nb=!value:* =!
- )
- )
-
- echo 本机IP为:%IP_Address%
- echo 子网掩码:%Subnet_Mask%
- echo 本机网关:%Default_Gateway%
- echo 首选 DNS:%DNS_Servers%
- echo 备用 DNS:%DNS_Servers2%
- pause
复制代码
|