快速切换本机IP

       我们公司的IP默认是自动获取的,但是偶尔自动获取的IP不能连接外网,手动设定一般可以解决。为了切换的方便,找了些资料,进行了加工组装,做成了一个方便切换静态或者DHCP的bat脚本。

代码如下,注意按提示修改为自己的对应IP参数,请保存为.bat扩展名。

@echo off 
title 更改本机IP
color 1f
echo -----------------------------------------
echo 若设置静态IP,请先在bat文件里指定相关参数
echo -----------------------------------------
rem eth           // 设置网卡名称,如"本地连接"
set eth="本地连接"
rem ip            // 设置IP地址
set ip=10.1.90.6
rem netmasks     //设置子网掩码
set netmasks=255.255.255.192
rem gw            // 设置网关
set gw=10.1.90.1
rem dns1         //设置主DNS
set dns1=10.1.36.101
rem dns2         //设置辅DNS
set dns2=202.106.0.20 

:doit
@echo off
set /p xz=执行手动指定的IP[a],执行自动获取[b]

if %xz%==a goto a
if %xz%==b goto b
goto doit
:a
@echo off
echo 正在添加【ip:%ip% /子网掩码:%netmasks% /网关:%gw%】
netsh interface ip set address "%eth%" static %ip% %netmasks% %gw%
echo 正在添加【主DNS:%dns1%】
netsh interface ip set dns "%eth%" static %dns1%
echo 正在添加【副DNS:%dns2%】
netsh interface ip add dns "%eth%" %dns2%

echo ---------------------------------
echo             done!
echo ---------------------------------
goto doit

:b
@echo off
netsh interface ip set address "%eth%" dhcp
netsh interface ip set dns "%eth%" dhcp
echo ---------------------------------
echo             done!
echo ---------------------------------
goto doit

效果:

QQ截图20130106182433

posted @ 2013-01-06 18:25  Aigle  阅读(598)  评论(0编辑  收藏  举报