卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章11201本站已运行3223

[python]一键断网联网,含bat代码

有时候在游戏,或者激活某些特殊软件时,需要临时断开网络,等处理完后,又要恢复网络,所以有了这个。

Python版,考虑到有的兄弟电脑上没有python环境,所以下面还有个bat版,使用附件下载的源码即可使用。


import os
 
 
def interface_info():
    for i in os.popen('netsh interface show interface'):
        if i := i.strip():
            ls = i.split()
    return ls[-1], ls[-3]
 
 
print(interface_info())
i_name, i_state = interface_info()
 
if i_state == '已连接':
    os.popen(f'netsh interface set interface {i_name} disable')
    print('连接已断开')
else:
    os.popen(f'netsh interface set interface {i_name} enable')
    print('连接已恢复')

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

 

 
一键联网断网.7z
87f41eb5b2d034478f1ec0072fc09cb7.7z (754 Bytes)
卓越飞翔博客
上一篇: js定时关闭的原生alert和confirm弹窗
下一篇: [Python 原创] 抖音爬虫(主页、喜欢列表全部下载)
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏