现在的位置: 首页 > 综合 > 正文

通过批处理轻松切换本机IP地址

2013年12月02日 ⁄ 综合 ⁄ 共 1439字 ⁄ 字号 评论关闭

 【作 者】:AcOol   【出 处】:酷客天堂

    很早前写过一个文章怎么用netsh来切换IP地址,其实已经讲过相关的内容,一时找不到那个文章放哪里了,-_-!!
    很多朋友像我一样总是拿着本子满世界乱跑的,到一个地方就的切换半天IP地址,网上也给了一些切换工具,包括IMB给小黑专门开发的管理工具,其实如果仅仅是为了日常几个地方的切换,通过批处理就可以轻松实现。
    下面我就把我常用的三个批处理放出来,注意我这里的“本地连接”已修改为“lan”,如果你用中文系统,记得吧lan改为"本地连接"。
    一、切换到DHCP模式:

@echo off
@net start dhcp
@netsh interface ip set address lan dhcp
echo The IP Address was Set DHCP successfully.
@netsh interface ip set dns lan dhcp
echo The IP DNS was Set DHCP successfully.

    注意:

1、注意修改lan为你的本地连接的名字,如果你使用的是简体中文版系统,默认就是"本地连接",记得加双引号。

    二、切换到公司IP地址:

@echo off
@net stop dhcp
@netsh interface ip set address lan static 192.168.0.30 255.255.255.0 192.168.0.254 1
echo The IP Address was Set 192.168.0.30 successfully.
@netsh interface ip set dns lan static 192.168.0.1 primary
echo The Primary DNS was Set successfully.
@netsh interface ip add dns lan 61.134.1.4 index=2
echo The Second DNS was Set successfully.
@netsh interface ip add dns lan 202.100.4.15 index=3

    注意:

1、注意修改lan为你的本地连接的名字,如果你使用的是简体中文版系统,默认就是"本地连接",记得加双引号。
2、192.168.0.30是我本机IP地址,255.255.255.0是子网掩码,192.168.0.254是我的默认网关,最后的1是越点数。
3、关于dns的设置一般朋友大概都只会设置第一个,其实加第二个和第三个都一样。

    三、切换回家中IP地址:

@echo off
@net stop dhcp
@netsh interface ip set address lan static 10.10.10.5 255.255.255.0 10.10.10.1 1
echo The IP Address was Set 10.10.10.5 successfully.
@netsh interface ip set dns lan static 61.232.202.158 primary
echo The Primary DNS was Set successfully.
@netsh interface ip add dns lan 202.100.4.15 index=2

    注意:

1、注意修改lan为你的本地连接的名字,如果你使用的是简体中文版系统,默认就是"本地连接",记得加双引号。
2、10.10.10.5是我本机IP地址,255.255.255.0是子网掩码,10.10.10.1是我的默认网关,最后的1是越点数。

    是不是很简单!

抱歉!评论已关闭.