Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn WiFi off using Python on Windows 10?

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.

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.

like image 899
Lain Avatar asked Oct 17 '25 03:10

Lain


1 Answers

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. Get the interface name

  2. 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")
    

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")      
like image 84
PyManiac Avatar answered Oct 19 '25 17:10

PyManiac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!