IP自动切换脚本

@echo off & cls & color 47 & mode con cols=80 lines=25 & title [IP自动切换工具]
cls
echo.

echo Cloud程序制作,于2011年6月6日.
echo.
echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
echo [1].一键换成网1                  [2].一键换成网2 
echo [3].一键换成网3                  [4].一键设置为动态
echo.
echo [5].退出
echo.
rem //设置变量
set NAME="本地连接"
rem //以下属性值可以根据需要更改
set ADDR=IP
set MASK=255.255.255.0
set GATEWAY=网关
set DNS1=61.177.7.1
set DNS2=8.8.8.8
rem //以上属性依次为IP地址、子网掩码、网关、首选DNS、备用DNS 

set ADDR1=
set MASK1=255.255.255.0
set GATEWAY1=
set DNS11=114.114.114.114
set DNS12=8.8.8.8
rem //以上属性依次为IP地址、子网掩码、网关、首选DNS、备用DNS 

set ADDR2=
set MASK2=255.255.255.252
set GATEWAY2=
set DNS21=114.114.114.114
set DNS22=8.8.8.8
rem //以上属性依次为IP地址、子网掩码、网关、首选DNS、备用DNS  

echo 请选择后回车:
set /p operate=
if %operate%==1 goto 1
if %operate%==2 goto 2
if %operate%==3 goto 3
if %operate%==4 goto 4
if %operate%==5 goto 5

:1
echo 正在设置静态IP,请稍等…
rem //可以根据你的需要更改
echo IP地址 = %ADDR%
echo 掩码 = %MASK%
echo 网关 = %GATEWAY%
netsh interface ipv4 set address name=%NAME% source=static addr=%ADDR% mask=%MASK% gateway=%GATEWAY% gwmetric=0 >nul
echo 首选DNS = %DNS1%
netsh interface ipv4 set dns name=%NAME% source=static addr=%DNS1% register=PRIMARY >nul
echo 备用DNS = %DNS2%
netsh interface ipv4 add dns name=%NAME% addr=%DNS2% index=2 >nul
echo 静态IP已设置!
pause
goto 5

:2
echo 正在设置静态IP,请稍等…
rem //可以根据你的需要更改
echo IP地址 = %ADDR1%
echo 掩码 = %MASK1%
echo 网关 = %GATEWAY1%
netsh interface ipv4 set address name=%NAME% source=static addr=%ADDR1% mask=%MASK1% gateway=%GATEWAY1% gwmetric=0 >nul
echo 首选DNS = %DNS11%
netsh interface ipv4 set dns name=%NAME% source=static addr=%DNS11% register=PRIMARY >nul
echo 备用DNS = %DNS12%
netsh interface ipv4 add dns name=%NAME% addr=%DNS12% index=2 >nul
echo 已设置!
pause
goto 5

:3
echo 正在设置静态IP,请稍等…
rem //可以根据你的需要更改
echo IP地址 = %ADDR2%
echo 掩码 = %MASK2%
echo 网关 = %GATEWAY2%
netsh interface ipv4 set address name=%NAME% source=static addr=%ADDR2% mask=%MASK2% gateway=%GATEWAY2% gwmetric=0 >nul
echo 首选DNS = %DNS21%
netsh interface ipv4 set dns name=%NAME% source=static addr=%DNS21% register=PRIMARY >nul
echo 备用DNS = %DNS22%
netsh interface ipv4 add dns name=%NAME% addr=%DNS22% index=2 >nul
echo 静态IP已设置!
pause
goto 5

:4
echo 正在设置动态IP,请稍等…
echo 正在从DHCP自动获取IP地址…
netsh interface ip set address "本地连接" dhcp
echo 正在从DHCP自动获取DNS地址…
netsh interface ip set dns "本地连接" dhcp
echo 动态IP已设置!
pause
goto 5

:5
exit

posted @ 2017-10-19 16:43  迷惘的云  阅读(854)  评论(0编辑  收藏  举报