Vista自动更改IP地址

来源:百度知道 编辑:UC知道 时间:2024/05/12 19:46:09
我用的Vista系统,需要经常在办公室和家里使用,但IP地址要经常更改,很麻烦,想求个BAT文件,可以自动转换IP地址。
公司的: IP为:172.18.0.69 子网掩码:255.255.255.0 默认网关:172.18.0.1 DNS:221.228.255.1
家里的: IP为:192.168.1.11 子网掩码:255.255.255.0 默认网关:192.168.1.1 DNS:221.6.96.177

@ echo off
rem 设置变量
set Nic=本地连接
rem //可以根据你的需要更改,
set Addr=192.168.0.2
set Mask=255.255.255.0
set Gway=192.168.0.1
set Dns1=61.134.1.4
set Dns2=218.30.19.40
rem //以上依次为IP地址、子网掩码、网关、首选DNS、备用DNS
echo ------------------------------------------------------
echo 正在进行IP设置,请稍等
rem //可以根据你的需要更改
echo. IP地址 = shy;dr%
echo. 子网掩码 = %Mask%
netsh interface ip set address name=%Nic% source=static addr=shy;dr% mask=%Mask% >nul
echo. 网关 = %Gway%
netsh interface ip set address name=%Nic% gateway=%Gway% gwmetric=1 >nul
echo. 首选DNS = %Dns1%
netsh interface ip set dns name=%Nic% source=static addr=%Dns1% register=PRIMARY >nul
echo. 备用DNS = %Dns2%
netsh interface ip add dns name=%Nic% addr=%Dns2% index=2 >nul
echo ------------------------------------------------------
echo IP设置完成!
netsh interface ip add dns name=%Nic% addr=%Dns3% index=2 >nul