bat代码实现一键断网联网(激活某些特殊软件时,需要临时断开网络)
[全站通告]付费处理问题,非诚勿扰,付出才有收获;有意加微信 2589053300 进行沟通处理
我们在安装某些特殊或者特定软件的时候,可能就会需要断开网络,很多时候我们需要关闭本地连接,然后开启,会感觉有些麻烦,就有了这个bat小助手需要临时断开网络,等处理完后,又要恢复网络,所以有了这个小玩意儿;
BAT版,功能与上面的一致
@echo off
for /f "tokens=2,4" %%i in ('netsh interface show interface') do (
set state=%%i
set name=%%j
)echo 当前:%name% %state%
if %state%==已连接 (
netsh interface set interface %name% disable
echo 连接已断开
) else (
netsh interface set interface %name% enable
echo 连接已恢复
)pause
Python版,需电脑有python环境
import os
def interface_name():
ls = []
for i in os.popen('netsh interface show interface'):
if i := i.strip():
ls.append(i.split())
return ls[-1][-1], ls[-1][-3]i_name, i_state = interface_name()
# print(interface_name())
if i_state == '已连接':
os.popen(f'netsh interface set interface {i_name} disable')
print('连接已断开')if i_state == '已断开连接':
os.popen(f'netsh interface set interface {i_name} enable')
print('连接已恢复')
一键断网联网下载地址如下-回复可见:
付费处理问题,非诚勿扰,付出才有收获;有意加微信2589053300 --更多请关注:老梁`s Blog
所写所说,是心之所感,思之所悟,行之所得;文当无敷衍,落笔求简洁。 以所舍,求所获;有所依,方所成!


看看线,多谢了!