桌面运维笔记合集
桌面运维合集
多网卡切换与路由添加小工具
用于批量配置交换机的小脚本
关于BIOS更新后pin失效且不能修改的情况如何解锁PC
win11开机跳过联网激活页面的方法
Windows 电脑 ping 不通启用规则
本文档使用 MrDoc 发布
-
+
首页
多网卡切换与路由添加小工具
适用于不会配置pc终端本机路由的初级阶段 ------------ 方便多网卡用户随用 bat脚本如下所示: ```bash @echo off chcp 65001 >nul set ETH1=以太网 set ETH2=以太网2 set ETH3=以太网3 echo 请选择要执行的网络切换操作: echo 1.启用金宏网 ::以太网卡是什么网络就填写什么网络 echo 2.启用政务外网 echo 3.启用互联网 echo. set /p choice=请输入数字 (1-3): if "%choice%"=="1" ( netsh interface set interface "%ETH1%" enabled netsh interface set interface "%ETH2%" disabled netsh interface set interface "%ETH3%" disabled echo %ETH1% 已启用! ) else if "%choice%"=="2" ( netsh interface set interface "%ETH2%" enabled netsh interface set interface "%ETH1%" disabled netsh interface set interface "%ETH3%" disabled echo %ETH2% 已启用! ) else if "%choice%"=="3" ( netsh interface set interface "%ETH2%" disabled netsh interface set interface "%ETH1%" disabled netsh interface set interface "%ETH3%" enabled echo %ETH2% 已启用! ) else ( echo 输入无效,必须为 1 或 2 或 3 ) pause ``` ==↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓== [【附件】网络切换.zip](/media/attachment/2025/02/%E7%BD%91%E7%BB%9C%E5%88%87%E6%8D%A2.zip) 适用于稍微会一点配置本机路由的中级阶段 ------------ 方便多网卡用户随用 bat脚本如下所示: ```bash @echo off setlocal enabledelayedexpansion chcp 65001 >nul :MAIN cls echo 可用网卡列表: echo ======================================== netsh interface show interface :: 临时文件路径 set temp_file=%temp%\wmic_output.txt :: 使用 wmic 获取数据并保存到临时文件 wmic nic where "NetConnectionID IS NOT NULL" get Name, NetConnectionID, InterfaceIndex > "%temp_file%" :: 使用 PowerShell 将 UTF-16 LE 文件转换为 UTF-8 powershell -Command "Get-Content -Path '%temp_file%' -Encoding Unicode | Set-Content -Path '%temp_file%.tmp' -Encoding UTF8; Move-Item -Path '%temp_file%.tmp' -Destination '%temp_file%' -Force" chcp 65001 >nul :: 读取并打印 UTF-8 文件内容 powershell -Command "Get-Content -Path '%temp_file%' -Encoding UTF8" :: 删除临时文件 del "%temp_file%" echo ======================================== echo. set /p "nember=请输入要配置的网卡索引号(InterfaceIndex下所示): " :INPUT_DETAILS echo. set /p "ip=请输入IP地址段(格式 192.168.1.10): " set /p "mask=请输入子网掩码(格式 255.255.255.0): " set /p "gateway=请输入网关地址(格式 192.168.1.1): " chcp 936 >nul :: 验证IP格式 echo %ip% | findstr /R "^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$" >nul chcp 65001 >nul if %errorlevel% neq 0 ( echo [错误] IP地址格式无效! goto INPUT_DETAILS ) chcp 936 >nul :: 计算网络地址 for /f "tokens=1-4 delims=." %%a in ("%ip%") do ( set ip1=%%a set ip2=%%b set ip3=%%c set ip4=%%d ) for /f "tokens=1-4 delims=." %%a in ("%mask%") do ( set /a mask1=%%a set /a mask2=%%b set /a mask3=%%c set /a mask4=%%d ) set /a net1=!ip1! & !mask1! set /a net2=!ip2! & !mask2! set /a net3=!ip3! & !mask3! set /a net4=!ip4! & !mask4! set "network=!net1!.!net2!.!net3!.!net4!" :: 添加永久路由 echo. chcp 65001 >nul echo 正在添加永久路由... chcp 936 >nul echo route -p add !network! MASK %mask% %gateway% IF %nember% route -p add !network! MASK %mask% %gateway% IF %nember% chcp 65001 >nul if %errorlevel% equ 0 ( echo [成功] 路由已添加! ) else ( echo [错误] 路由添加失败! ) pause goto MAIN ``` ==↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓== bat: [【附件】添加路由.zip](/media/attachment/2025/02/%E6%B7%BB%E5%8A%A0%E8%B7%AF%E7%94%B1.zip) exe: [【附件】尝鲜小软件.zip](/media/attachment/2025/02/%E5%B0%9D%E9%B2%9C%E5%B0%8F%E8%BD%AF%E4%BB%B6.zip)
taroter
2025年2月14日 00:40
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码