Bottom Page

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
You like this post
Quote
#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.
You like this post
Quote
#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
You like this post
Quote
#4
Do you know how to enable or disable the wireless connection from a terminal in your OS (without python at all)?
You like this post
Quote
#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
You like this post
Quote
#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!")
You like this post
Quote
#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.
You like this post
Quote
#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.
You like this post
Quote
#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
You like this post
Quote
#10
Hello,
I tried to use this code and modify, looks like it doesn't do anything.
any suggestions, Please
[icode]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")[/icode]

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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Not able to Read byte Array From Wireless Coordinator jenkins43 0 44 Mar-18-2019, 07:05 AM
Last Post: jenkins43
  SSAS Connection ray67 1 70 Feb-28-2019, 05:34 PM
Last Post: Larz60+
  Read data of Wireless Modem in Byte Format barry76 2 138 Jan-31-2019, 11:26 AM
Last Post: barry76
  cefpython3. JS and Python connection ioprst 0 140 Jan-30-2019, 09:04 AM
Last Post: ioprst
  Connection with SQL Server DionisiO 0 104 Jan-27-2019, 01:11 PM
Last Post: DionisiO
  Does Python sqlite3 detect connection errors zatlas1 6 223 Jan-18-2019, 06:02 AM
Last Post: zatlas1
  How to detect wireless modem connected serially to my laptop in python barry76 3 261 Jan-08-2019, 06:18 AM
Last Post: Gribouillis
  Code Wireless Temperature sensor and send sensor readings to google sheet jenkins43 0 201 Nov-29-2018, 12:44 PM
Last Post: jenkins43
  Connection with firebird using python nick722 0 315 Nov-23-2018, 03:40 PM
Last Post: nick722
  Socket connection and thread tracking... MuntyScruntfundle 2 237 Oct-21-2018, 02:55 AM
Last Post: Skaperen

Forum Jump:


Users browsing this thread: 1 Guest(s)