04
十二

多重网络环境下动态切换TCP/IP网络配置的批处理文件

移动办公或多重网关的网络环境下,经常需要切换网络配置,为了图方便写了一组切换IP的脚本。

具体用法是在命令行执行“ConfigNet.bat IP1"切换到网络环境1,……,执行"ConfigNet.bat IPn”切换到网络环境N.

注: 如果多重网络环境不是同时运作,可以考虑使用windows系统网络的特性,为网络设置多重网络地址, 操作系统可根据还环境自行切换.

 

1. 建立网络环境1下的shell文件,IP1.sh

其中,文件中的**IP1需要替换为对应于网络环境1下的各IP地址。IP1.sh的内容如下:

#IP1.sh

# Interface configuration
        pushd interface
        reset all
        popd

# Interface IP Configuration        
        pushd interface ip

  set address name = "本地连接" source = static addr = yourIP1 mask = yourMaskIP1
       set address name = "本地连接" gateway = yourGateWayIP1 gwmetric = 1
       set dns name = "本地连接" source = static addr = yourDnsIP1
      #add dns name = "本地连接" addr = youDnsIP2
       set wins name = "本地连接" source = static addr = none

popd
# End of interface IP configuration

2.建立网络环境N下的shell文件IPn.sh

文件的内容如第一节中网络环境1下类似,修改对应的IP1为网络环境N下的对应IP即可。

3.建立批处理文件ConfigNet.bat

建立作为swith,切换调用sh文件的批处理文件confignet.bat,内容大致如下:

IF "%~1"=="IP1" goto net_IP1
     IF "%~1"=="IPn" goto net_IPn
     IF "%~1"=="" goto end

:net_IP1
      netsh exec IP1.sh
      goto end

:net_IPn
      netsh exec IPn.sh
      goto end

:end

VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)

1 条评论了已经

Trackbacks/Pingbacks.

发表评论

名字(必须)
邮箱(必须),(永不被公布)
网址(建议)

字体为 粗体 是必填项目,邮箱地址 永远不会 公布。

允许部分 HTML 代码:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URLs(网站链接)必须完整有效 (比如: http://www.bi-professional.com),所有标签都必须完整的关闭。

超出部分系统将会自动分段及换行。

请保证评论内容是与日志或 Blog 内容相关的,灌水、攻击性或不恰当的评论 可能 会被编辑或删除。