Python Forum
Enable & Disable Wireless connection by using python
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enable & Disable Wireless connection by using python
#1
Sorry if you find this questions very easy and basic for you. I am New in Python and trying to learn every day.

My Questions: How can I disable and enable Wi-Fi/ Wireless network by using Python?

My Goal is to, Create and GUI with 2 buttons, i will enable the Wifi and another one will disable the Wifi, where the user can click to disable and enable the Wi-Fi network.

Please help and advise. Thank you
Reply
#2
If you know how to do it from a terminal, you can readily call the command from a python script with the subprocess module.
Reply
#3
(Jan-14-2019, 04:11 PM)Gribouillis Wrote: If you know how to do it from a terminal, you can readily call the command from a python script with the subprocess module.

Hello Griboullis, Thanks for your reply.
I was using Tkinter GUI to create 2 buttons and i don't know which library or function should I use.
Hope this will help.
Thanks
MP
Reply
#4
Do you know how to enable or disable the wireless connection from a terminal in your OS (without python at all)?
Reply
#5
(Jan-14-2019, 04:17 PM)Gribouillis Wrote: Do you know how to enable or disable the wireless connection from a terminal in your OS (without python at all)?

Yes, i do have the script.
Quote:netsh interface set interface "Wi-Fi" DISABLED
Quote:netsh interface set interface "TPALANDOC" ENABLED

and it works perfectly. but i want to make it more user-friendly.
Please advise.
Thank you
MP
Reply
#6
Then you can use (for python >= 3.5)
import subprocess
result = subprocess.run(["netsh", "interface", "set", "interface", "Wi-Fi", "DISABLED"])
print("FAILED..." if result.returncode else "SUCCESS!")
Reply
#7
(Jan-14-2019, 04:25 PM)Gribouillis Wrote: Then you can use (for python >= 3.5)
import subprocess
result = subprocess.run(["netsh", "interface", "set", "interface", "Wi-Fi", "DISABLED"])
print("FAILED..." if result.returncode else "SUCCESS!")

Thank you ,
I am getting the following error, even though i am running cmd as Administrator
Quote:The requested operation requires elevation (Run as administrator).

FAILED...
Please advise.
Thank you
MP.
Reply
#8
I dont know windows well enough, but you can try to add 'runas', '/noprofile', '/user:Administrator', before 'netch'. Another solution would perhaps be to run your tkinter script as administrator.
Reply
#9
(Jan-14-2019, 04:57 PM)Gribouillis Wrote: I dont know windows well enough, but you can try to add 'runas', '/noprofile', '/user:Administrator', before 'netch'. Another solution would perhaps be to run your tkinter script as administrator.

Hi Gribouillis,
Thanks for your reply and solutions, But it did work for me.
Sorry about it.
Thanks for your help.
Manam
Reply
#10
Hello,
I tried to use this code and modify, looks like it doesn't do anything.
any suggestions, Please
import os
os.system("netsh interface show interface")

def enable():
os.system("netsh interface set interface 'Wi-Fi' enabled")

def disable():
os.system("netsh interface set interface 'Wi-Fi' disabled")


My Output:
Quote:My OutPut:
Admin State State Type Interface Name
-------------------------------------------------------------------------
Enabled Connected Dedicated Wi-Fi
Disabled Disconnected Dedicated TPALAN


Process finished with exit code 0

Thanks
MP
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I don't know what is wrong (Python and SQL connection) shereen 2 158 Yesterday, 06:46 PM
Last Post: menator01
  No Internet connection when running a Python script basil_555 8 443 Mar-11-2024, 11:02 AM
Last Post: snippsat
  Connection LTspice-Python with PyLTSpice bartel90 0 281 Feb-05-2024, 11:46 AM
Last Post: bartel90
  Virtual Env changing mysql connection string in python Fredesetes 0 325 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  connection python and SQL dawid294 4 587 Dec-12-2023, 08:22 AM
Last Post: Pedroski55
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 679 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Errors when trying to disable tkinter checkbutton rrick_88 7 2,753 Feb-17-2022, 10:30 PM
Last Post: deanhystad
  Python MYSQL connection does not work after 1h idle zazas321 9 6,624 Oct-07-2021, 12:02 PM
Last Post: ndc85430
  Serial connection connection issue Joni_Engr 15 7,838 Aug-30-2021, 04:46 PM
Last Post: deanhystad
  wireless access point on raspberry PI zazas321 0 1,902 Oct-02-2020, 05:33 PM
Last Post: zazas321

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020