改得两个Windows下更改网络配置的脚本

其实我一直不把批处理当脚本的,不过其实它也很强大,而且其实我还颇离不开windows。

固定IP与DHCP之间切换,主要调用netsh实现:


@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:START
set NAME="Local Area Connection"
set FIXXED_IP=172.24.179.73
set FIXXED_MASK=255.255.255.0
set FIXXED_GATEWAY=172.24.179.1
set FIXXED_DNS1=172.24.222.90
set FIXXED_DNS2=172.24.12.253
set FIXXED_DNS3=172.24.208.127
set FIXXED_DNS4=135.251.34.36
set FIXXED_WINS1=172.24.208.86
set FIXXED_WINS2=172.24.208.98
set FIXXED_WINS3=135.254.108.83
set FIXXED_WINS4=135.254.108.82
goto :SELECT_POS
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SELECT_POS
set /p POS= Select configuration(1:FIXXED. 2:DHCP. 3:Exit) :
if /i %POS%==1 goto :FIXXED
if /i %POS%==2 goto :DHCP
if /i %POS%==3 goto :SETEND
echo. Input error!!!
goto :SELECT_POS
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:FIXXED
echo. Setting IP as FIXXED environment...
netsh interface ip set address %NAME% static %FIXXED_IP% %FIXXED_MASK% %FIXXED_GATEWAY% 1 >%TEMP%/null
echo. Address setting finished.
netsh interface ip set dns %NAME% static %FIXXED_DNS1% primary >%TEMP%/null
netsh interface ip add dns %NAME% %FIXXED_DNS2% >%TEMP%/null
netsh interface ip add dns %NAME% %FIXXED_DNS3% >%TEMP%/null
netsh interface ip add dns %NAME% %FIXXED_DNS4% >%TEMP%/null
echo. DNS setting finished.
netsh interface ip set wins %NAME% static %FIXXED_WINS1% >%TEMP%/null
netsh interface ip add wins %NAME% %FIXXED_WINS2% >%TEMP%/null
netsh interface ip add wins %NAME% %FIXXED_WINS3% >%TEMP%/null
netsh interface ip add wins %NAME% %FIXXED_WINS4% >%TEMP%/null
echo. WINS setting finished.
echo. All done.
goto :SETEND
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DHCP
echo. Setting IP as DHCP environment...
netsh interface ip set address %NAME% dhcp >%TEMP%/null
echo. Address setting finished.
netsh interface ip set dns %NAME% dhcp >%TEMP%/null
echo. DNS setting finished.
netsh interface ip set wins %NAME% dhcp >%TEMP%/null
echo. WINS setting finished.
echo. All done.
goto :SETEND
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SETEND
pause

代理服务器与不用代理服务器之间切换,通过调用reg修改注册表相应键值实现:


@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:START


goto :SELECT_PROXY
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SELECT_PROXY
set /p PROXY= Select PROXY(1:LOCAL. 2:NONE. 3:Exit) :
if /i %PROXY%==1 goto :LOCAL
if /i %PROXY%==2 goto :NONE
if /i %PROXY%==3 goto :SETEND
echo. Input error!!!
goto :SELECT_PROXY
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:LOCAL
echo. Setting...
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f >%TEMP%/null
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "172.24.179.133:8000" /f >%TEMP%/null
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "localhost;10.*;172.*;*alcatel*;*sbell*" /f >%TEMP%/null
echo. All done.
goto :SETEND
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:NONE
echo. Setting...
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f >%TEMP%/null
echo. All done.
goto :SETEND
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SETEND
pause

Comments

Leave a Reply