在 Windows 10 上使用 Python 关闭 WiFi? [英] Turn WiFi off using Python on Windows 10?

查看:53
本文介绍了在 Windows 10 上使用 Python 关闭 WiFi?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种使用脚本打开和关闭 wifi 的方法.我想这可以通过进入飞行模式或其他一些方法来完成.当我在谷歌上搜索答案时,虽然我找不到任何对 Windows 有用的东西,但只对 android 甚至 macOS 有用.

I have been looking for a way to toggle my wifi on and off using a script. I figured this could be done maybe by entering airplane mode or some other method. When I was googleing for the answer though I could not find anything useful for windows, just for android and even macOS.

任何人都有两个功能,一个用于关闭 wifi,一个用于重新打开它?或者从特定的连接/断开连接也有效.如果相关,它是我的默认 wifi.

Anyone have a 2 functions, one for turning wifi off, and one for turning it back on? Or connecting/disconnecting from a specific one works too. It is my default wifi if this is relevant.

推荐答案

Python 无法直接访问您的 Wifi 适配器,但 Windows 可以.因此,您可以使用 os 模块来运行命令提示代码并控制您的 wifi 适配器.

Python does not have direct access to your Wifi Adapter but windows does. So you can use os module to run commmand prompt codes and control your wifi adapter.

  1. 获取接口名称

  1. Get the interface name

然后你就可以用这个名字来运行开/关命令

Then you can just use the name to run on/off commands

# Get the interface name using this script.
import os 
os.system("netsh interface show interface")

然后在此脚本中将其替换为 Wifi 以开始使用.

Then replace it with Wifi in this script to get going.

import os 
def enable():
    os.system("netsh interface set interface 'Wifi' enabled")

def disable():
    os.system("netsh interface set interface 'Wifi' disabled")      

这篇关于在 Windows 10 上使用 Python 关闭 WiFi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆