thankinglove 2015-09-06
@echo off set ::请根据您的参数修改以下数据 ::设置 IP地址 set ipaddress=192.168.10.43 ::设置 子掩码 set mask=255.255.254.0 ::设置 网关 set gateway=192.168.10.1 ::设置 首选DNS服务器 set dns1=220.189.127.106 ::设置 备用DNS服务器 set dns2=220.220.127.107 ::请根据您的参数修改以上数据 set /p type=请选择设置方式,1: 静态,2: 动态: if /i %type%==1 goto :STATIC_IP if /i %type%==2 goto :DHCP_IP :STATIC_IP echo 正在进行静态IP设置,请稍等... netsh interface ip set address name=%name% source=static addr=%ipaddress% mask=%mask% echo. IP地址 = %ipaddress% .完成设置 echo. 子掩码 = %mask% .完成设置 netsh interface ip set address name=%name% gateway=%gateway% gwmetric=1 >nul echo. 网关 = %gateway% .完成设置 netsh interface ip set dns name=%name% source=static addr=%dns1% register=PRIMARY >nul echo. 首选DNS = %dns1% .完成设置 netsh interface ip add dns name=%name% addr=%dns2% index=2 >nul echo. 备用DNS = %dns2% .完成设置 goto :SETEND :DHCP_IP echo 正在进行动态IP设置,请稍等... netsh interface ip set address name=%name% source=dhcp netsh interface ip set dns name=%name% source=dhcp register=PRIMARY netsh interface ip set wins name=%name% source=dhcp goto :SETEND :SETEND echo. ===============IP设置完成================ echo. ========================================= echo. == 以下测试网络是否正常 echo. == 若出现如下形式: echo. == "Reply from %gateway%: bytes=32 time<1ms TTL=64" echo. == 则网络正常,否则网络不正常! echo. ========================================= ping %gateway% -n 1 pause