中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-11 13:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 网关自动切换脚本 查看 620 回复 1
楼 主 网关自动切换脚本 发表于 2009-03-06 02:59 ·  中国 北京 歌华有线
新手上路
积分 1
发帖 1
注册 2008-07-03 22:28
18年会员
UID 121072
性别 男
状态 离线
: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
2 发表于 2009-03-11 10:12 ·  中国 四川 南充 营山县 电信
超级版主
★★★★
我爱DOS
积分 5,310
发帖 2,044
注册 2005-09-26 12:00
20年会员
UID 42843
性别 男
来自 四川南充
状态 离线
论坛跳转: