标题: [网络连接] 批处理自动更改DNS时使用for语句如何嵌套if跳转语句? [打印本页]
作者: lizhiqiang19 时间: 2009-10-22 22:06 标题: 批处理自动更改DNS时使用for语句如何嵌套if跳转语句?
我有一个自动判断本地连接名称并更改DNS的脚本,其中的一部分如下:- echo 清理现有DNS
- echo 现有的连接名如下:
- for /f "skip=2 tokens=2,* " %%i in ('netsh interface show interface') do (
- set netname=%%j
- if "%%j"=="环回" goto back
- if "%%j"=="内部" goto back
- netsh interface ip delete dns name="%%j" addr=all >nul
- netsh interface ip add dns name="%%j" addr=%dns1% index=1 >nul
- netsh interface ip add dns name="%%j" addr=%dns2% index=2 >nul
- :back
- pause>nul)
复制代码
在这段代码中我的本意是如果检测到本地连接名为“环回”或者“内部”的时候不对其DNS做更改,并继续执行循环知道完成,但目前我只能加跳转,请问for中嵌套IF跳转语句怎么处理
作者: bhsx 时间: 2009-10-23 01:20
用CALL
- @echo off
- for %%i in (3 2 3 4 8 87 7 76 6 7) do call:asd %%i
- goto:eof
- :asd
- echo %*
- goto:eof
复制代码
作者: inittab 时间: 2009-10-23 08:58
可以这样。
if not "%%j"=="环回" if not "%%j"=="内部" (
...
)
取消goto
作者: lizhiqiang19 时间: 2009-10-23 13:31
楼上,那如果检测到“%%j==环回”的话,我需要跳过对“环回”连接的设置,而继续执行循环并检测设置下一个连接名怎么办?
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |