标题: 网关自动切换脚本
[打印本页]
作者: lvchunming
时间: 2009-3-6 02:59
标题: 网关自动切换脚本
:start
@echo off
rem 定义网关变量:
ipconfig >ipconfig.txt
if exist GateIP.txt del GateIP.txt
find " Default Gateway . . . . . . . . . : 192" ipconfig.txt >GateIP.txt
for /f "skip=2 tokens=13" %%G in (GateIP.txt) do set GateIP=%%G
rem 测试网络连通性:
ping -n 1 -w 100 211.100.2.125
goto state%ERRORLEVEL%
rem 连通性正常:
:state0
echo 连通性正常
PAUSE
goto end
rem 连通性失败:
:state1
if '%GateIP%' == '192.168.0.1' goto gateway1
if '%GateIP%' == '192.168.0.2' goto gateway2
:gateway1
echo 更换成网关2
rem PAUSE
route delete 0.0.0.0 mask 0.0.0.0
route add 0.0.0.0 mask 0.0.0.0 192.168.0.2
goto start
:gateway2
echo 更换成网关1
rem PAUSE
route delete 0.0.0.0 mask 0.0.0.0
route add 0.0.0.0 mask 0.0.0.0 192.168.0.1
goto start
:end
choice /c:a /t:n,5
if errorlevel 1 goto
作者: 不得不爱
时间: 2009-3-11 10:12
反复切换网关干什么
是切换内网和外网吗?