17
2025
07

公司vpn拨号后指定网段走公司vpn脚本

一、添加路由

@echo off
:: 1. 管理员权限检查
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if %errorlevel% neq 0 (echo 请以管理员身份运行! & exit /b 1)

:: 2. 设置固定VPN网关
set vpn_gateway=192.168.170.1

:: 3. 添加公司网段路由(192.168.88.0/24)
route add 192.168.88.0 mask 255.255.255.0 %vpn_gateway% -p >nul
if %errorlevel% equ 0 (
    echo ✓ 路由添加成功:192.168.88.0/24 -> %vpn_gateway%
) else (
    echo ✗ 路由添加失败!错误码: %errorlevel%
)

:: 4. 验证路由
echo; & echo 路由表检查:
route print | findstr 192.168.88.0
pause