Turn WiFi off using Python on Windows 10?

Viewed 11205

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.

4 Answers
os.system(f'netsh {iface_type} connect {iface_name}')

os.system(f'netsh {iface_type} disconnect')

updated netsh wifi commands for 2022 for anyone who needs them

netsh interface set interface name = "Wi-fi" enabled

netsh interface set interface name = "Wi-fi" disabled

Just replace ' with "

You need administrator rights to use this command

All you need to do is take the space out and it works for me.

For example: use interface name = "Wi-Fi2" with the code above.

Related