目前笔记本同时连接有线和无线,想通过wmic NICCONFIG where "IPEnabled='TRUE' and DHCPEnabled='TRUE'" 获取两个网卡的信息,但以下脚本输出的文本只能显示一个网卡信息,求大佬完善脚本,要求有中文注释并输出效果如图。
脚本如下:- @echo off&setlocal enabledelayedexpansion
- set apath="E:\Mydata\%Username%\Desktop\ip地址.txt"
- echo >%apath%
-
- for /f %%i in ('hostname') do set a=%%i
- echo 计算机名:%a%>>%apath%
-
- for /f %%i in ('whoami') do set a=%%i
- echo 登陆用户:%a%>>%apath%
-
- for /f %%i in ('set logonserver') do set a=%%i
- echo 登陆哪台域:%a%>>%apath%
-
- echo;>>%apath%
-
- for /f "tokens=1,2,3 delims=={,}" %%a in ('wmic NICCONFIG where "IPEnabled='TRUE' and DHCPEnabled='TRUE'" get Description^,MacAddress^,DefaultIPGateway^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value^|findstr "="') do (
- if "%%a"=="Description" (set "Name=%%~b"
- ) else if "%%a"=="DefaultIPGateway" (set "Gate=%%~b"
- ) else if "%%a"=="DNSServerSearchOrder" (set "DSN1=%%~b"&set "DSN2=%%~c"
- ) else if "%%a"=="IPAddress" (set "IP=%%~b"
- ) else if "%%a"=="IPSubnet" (set "Mask=%%~b"
- ) else if "%%a"=="MACAddress" (set "MAC=%%~b"
- ) else if "%%a"=="ServiceName" (set "Chip=%%~b")
- if defined Gate if defined Chip goto :show
-
- )
- :show
- echo;网卡名称:%Name%>>%apath%
- echo;IP地址:%IP%>>%apath%
- echo;子网掩码:%Mask%>>%apath%
- echo;默认网关:%Gate%>>%apath%
- echo;首选DNS:%DSN1%>>%apath%
- echo;备用DNS:%DSN2%>>%apath%
- echo;MAC地址:%MAC%>>%apath%
-
- ::pause
- ::start %apath%
复制代码
|