2015-10-09 66 views
0

我已經批量編寫了幾條命令,可以在選擇的基礎上執行它們。我使用2個IP地址,每次在IP之間切換時都必須更改IPv4和DNS。批量更改IP和DNS的命令

我已經完成了這段代碼,如果我一行一行地執行但是在批處理中他們給出了錯誤,這個工作正常。

@ECHO OFF 
SET /P no= Welcome dude so what are you up to press 1 for buzznet,2 for BSNL : 

IF "%NO%"=="1" GOTO BUZZ 
IF "%NO%"=="2" GOTO BSNL 

:BUZZ 
netsh interface ipv4 set address name="Ethernet" source=static^
     addr=192.168.22.19 mask=255.255.255.0 gateway=192.168.22.1 
netsh interface ip add dns name="Ethernet" addr=192.168.18.1 
netsh interface ip add dns name="Ethernet" addr=8.8.8.8 index=2 

:BSNL 
netsh interface ip set address "Ethernet" dhcp 
netsh interface ip set dns 「Ethernet」 dhcp 
pause 

enter image description here

+0

你會得到什麼樣的錯誤? – TDG

+0

更正的語法。 – Chuck

+0

使用變量與周圍'%'(在開始和結束時)'%NO'沒有意義,它應該是'%NO%'。刪除'@echo off'來查看哪一行正在生成錯誤消息。 – Stephan

回答

0

如您需要添加的東西時停止作業完成腳本繼續評論說。 (goto:EOFexit /b 0

@ECHO OFF 

:retry 
SET /P no= Welcome dude so what are you up to press 1 for buzznet,2 for BSNL : 

IF "%no%"=="1" GOTO BUZZ 
IF "%no%"=="2" GOTO BSNL 
rem if %no% is not 1 nor 2 then exit or goto :retry. 
exit /b 0 

:BUZZ 
netsh interface ipv4 set address name="Ethernet" source=static^
     addr=192.168.22.19 mask=255.255.255.0 gateway=192.168.22.1 
netsh interface ip add dns name="Ethernet" addr=192.168.18.1 
netsh interface ip add dns name="Ethernet" addr=8.8.8.8 index=2 
rem job done, then exit with a pause before 
pause 
exit /b 0 

:BSNL 
netsh interface ip set address "Ethernet" dhcp 
netsh interface ip set dns "Ethernet" dhcp 
pause 

而且最後一個命令用引號「Ethernet」畸形應"Ethernet"

+0

label':retry'應該在'set/p'之前移動,否則你創建一個無限循環。 – Stephan

+0

感謝它的幫助 –