标题: [网络连接] 【已解决】请教,批处理获取多网卡系统中指定网络连接对应的网关子网掩码DNS [打印本页]
作者: godkong 时间: 2018-3-8 08:45 标题: 【已解决】请教,批处理获取多网卡系统中指定网络连接对应的网关子网掩码DNS
本帖最后由 godkong 于 2018-3-8 22:59 编辑
- @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 :ShowResult
- )
-
- :ShowResult
- set "IP=%IP: =%"
- echo,你的IP是:%IP%
- pause
复制代码
此为论坛大神Batcher 的杰作,只提取显示了IP地址,我现在要实现同时显示子网掩码、网关、主备DNS地址,5个信息,请教各位大神批处理改怎么写?
[quote]终于成功了,感谢Batcher大神的批处理。
godkong 发表于 2018-3-8 22:46
[/quote]
作者: godkong 时间: 2018-3-8 22:18
- @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 "默认网关"') do (
- set "gateway=%%i"
- goto :ShowResult
- )
-
-
- :ShowResult
- set "gateway=%gateway: =%"
- echo,%gateway%
- pause
复制代码
这样能显示网关,但同时显示IP和网关要怎么修改代码?
作者: godkong 时间: 2018-3-8 22:30
- @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 :ShowResult
- )
-
- :ShowResult
- set "IP=%IP: =%"
- set "MAC=%MAC: =%"
- echo,%IP%,%MAC%
- pause
复制代码
这样可以同时显示IP和MAC地址,但是死活不会修改,按照理解去修改,死活搞不出DNS服务器的显示
作者: godkong 时间: 2018-3-8 22:41
- @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 "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
复制代码
显示五个信息的代码,为什么DNS服务器地址不能显示,代码怎么修改?
作者: godkong 时间: 2018-3-8 22:46
- @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大神的批处理。
作者: godkong 时间: 2018-3-8 22:53
备用DNS好像无法t提取并显示出来,大神们有办法吗?
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |