请注意,本文编写于 361 天前,最后修改于 361 天前,其中某些信息可能已经过时。
有时候在游戏,或者激活某些特殊软件时,需要临时断开网络,等处理完后,又要恢复网络,所以有了这个。
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('连接已恢复')
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
1 条评论
挺好的小玩意