- @echo off
- REM 设置网络适配器的名称
- REM 英文系统一般是:Local Area Connection
- REM set "AdapterName=Local Area Connection"
- REM 中文系统一般是:无线网络连接
- set "AdapterName=无线网络连接"
-
- set "FileTmp=%temp%\ipList.txt"
- ipconfig /all >"%FileTmp%"
- for /f "delims=:" %%i in ('findstr /n /c:"%AdapterName%" "%FileTmp%"') do (
- set "SkipRow=%%i"
- goto :DoSkip
- )
-
- :DoSkip
- for /f "tokens=2 delims=:(" %%i in ('more +%SkipRow% "%FileTmp%" ^| findstr /v "IPv6" ^|findstr "IP"') do (
- set "IP=%%i"
- goto :DoSkip1
- )
-
- :DoSkip1
- for /f "tokens=2 delims=:" %%i in ('more +%SkipRow% "%FileTmp%" ^| findstr "..-..-..-..-..-.."') do (
- set "MAC=%%i"
- goto :DoSkip2
- )
-
- :DoSkip2
- for /f "tokens=2 delims=:" %%i in ('more +%SkipRow% "%FileTmp%" ^| findstr "子网掩码"') do (
- set "mask=%%i"
- goto :DoSkip3
- )
-
- :DoSkip3
- for /f "tokens=2 delims=:" %%i in ('more +%SkipRow% "%FileTmp%" ^| findstr "默认网关"') do (
- set "gateway=%%i"
- goto :DoSkip4
- )
-
- :DoSkip4
- for /f "tokens=2 delims=:" %%i in ('more +%SkipRow% "%FileTmp%" ^| findstr /v "router" ^| findstr "DNS 服务器"') do (
- set "dns=%%i"
- goto :ShowResult
- )
-
- :ShowResult
- set "IP=%IP: =%"
- set "MAC=%MAC: =%"
- set "mask=%mask: =%"
- set "gateway=%gateway: =%"
- set "dns=%dns: =%"
- echo,你的IP是:%IP%
- echo,你的物理地址是:%MAC%
- echo,你的子网掩码是:%mask%
- echo,你的网关是:%gateway%
- echo,你的DNS服务器地址是:%dns%
- pause
复制代码 终于成功了,感谢Batcher大神的批处理。 |