通过命令行脚本实现双网卡切换 您所在的位置:网站首页 快捷指令库5g切换网络 通过命令行脚本实现双网卡切换

通过命令行脚本实现双网卡切换

2023-09-14 05:52| 来源: 网络整理| 查看: 265

作者:iamlaosong

工作中我们会偶尔启用、禁用网卡,一般都是通过图形界面完成。可是如果经常使用,这样做就比较麻烦,通过命令行写成脚本文件放到桌面就会比较方便,最近就碰到这种情况。电脑插了两块网卡,一块接内网,一块接外网。 电脑同时连接内外网存在安全隐患,管理规定严禁使用双网卡,所以,安全起见,同一时刻只能使用一块网卡。

最安全办法是使用哪块网卡,就插哪个网线,拔掉另一块网卡的网线,不过这个办法比较麻烦,简单的方法就是网线都插上,但只启用一块网卡,启用一块网卡时,禁用另一块网卡。这个打开网卡配置属性窗口可以轻松完成,但用命令行完成会更加方便。当然,这个方法还是有安全隐患的,只能短时使用,黑客可以通过技术同时启用两块网卡,实现内外网互通。

1、首先要知道网络连接名称,这个可以通过图形界面查看,也可以通过命令查看,如下图:

注意,这个网络是可以修改的,就像修改文件名一样修改。右击网络连接图标,弹出菜单中就有“重命名”(或者按F2也可以),如下图所示:

2、其次,创建两个命令脚本文件放在桌面上,使用启用、禁用网卡命令

新建一个文本文件,文件名为“启用外网.bat”,输入下列文本:

@echo off netsh interface set interface 内网10 disabled netsh interface set interface 外网192 enabled

同样,再新建一个反向的命令文件“启用内网.bat”,输入下列文本:

@echo off netsh interface set interface 外网192 disabled netsh interface set interface 内网10 enabled

注意:disabled放前面,先禁用后启用,杜绝双网卡同时激活。

3、最后,使用的时候双击对应的文件执行即可。

4、实际使用时,采用菜单方式更方便:

@echo off :start cls echo   内外网启动批处理 echo. echo 1-启用外网关闭内网 echo. echo 2-启用内网关闭外网 echo. echo 3-启用内外网 echo. echo 4-关闭内外网 echo. echo 0-退出 echo.

set /p UserChoice=请选择: if "%UserChoice%"=="0" goto 0 if "%UserChoice%"=="1" goto 1 if "%UserChoice%"=="2" goto 2 if "%UserChoice%"=="3" goto 3 if "%UserChoice%"=="4" goto 4 goto start

:0 exit :1 netsh interface set interface 内网10 disabled netsh interface set interface 外网192 enabled exit

:2 netsh interface set interface 外网192 disabled netsh interface set interface 内网10 enabled exit

:3 netsh interface set interface 外网192 enabled netsh interface set interface 内网10 enabled exit

:4 netsh interface set interface 外网192 disabled netsh interface set interface 内网10 disabled exit  



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有