自动添加静态路由

-----------打开TXT,以下内容另存为.bat文件后执行-------------------

@echo off & Setlocal enabledelayedexpansion
color f9
Title 命令
:begin
cls
echo 请选择操作:
echo 1、添加内网路由
echo 2、删除内网路由
echo 3、退出
set /P Choice= 请输入要执行操作的数字,然后回车:
If not "%Choice%"=="" (
If "%Choice%"=="1" (goto :add) else If "%Choice%"=="2" (goto :del) else If "%Choice%"=="3" (exit) else (echo 输入错误请重新输入)

)
pause >nul
goto :begin

:add
cd . >c:\ip.txt
for /f "tokens=2 skip=2 delims='[]'" %%i in ('nbtstat -n') do (
set "ip=%%i"
echo !IP! >>c:\ip.txt
)
for /f "tokens=1-4 delims=." %%a in (c:\ip.txt) do (
set "mask=%%a.%%b.%%c"
if /I !mask! EQU 192.168.3 (route add -p 192.168.4.0 mask 255.255.240.0 192.168.3.201 && route add -p 192.168.2.0 mask 255.255.255.0 192.168.3.201 ) else if /I !mask! EQU 192.168.4 (route add -p 192.168.3.0 mask 255.255.255.0 192.168.4.221 && route add -p 192.168.2.0 mask 255.255.255.0 192.168.4.221 ) else if /I !mask! EQU 192.168.2 (route add -p 192.168.3.0 mask 255.255.255.0 192.168.2.2 && route add -p 192.168.4.0 mask 255.255.240.0 192.168.2.2 ) else (echo 请检查是否为内网!)
)
echo 添加办公路由操作完成
pause >nul
goto :begin

:del
route delete 192.168.2.0
route delete 192.168.3.0
route delete 192.168.4.0

echo 删除路由操作完成
pause >nul
goto :begin

posted on 2019-10-16 11:33  人生如梦既梦如人生  阅读(772)  评论(0编辑  收藏  举报

导航