Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn on/off wifi with python on osx

It may be because of my ISP provider, sometimes when I am away, internet is down and it doesn't work until I restart wifi connection. So my script begins to raise timeout exception until I turn off and then turn on the wifi connection. Is there a efficent way to turn wifi on/off automatically with python 2.7 on osx el capitan?

like image 753
hzleonardo Avatar asked Dec 13 '25 08:12

hzleonardo


1 Answers

SOLUTION:

The easier and more efficent way to do this without using any complex or subprocess module:

import os 
os.system("networksetup -setairportpower airport off")
os.system("networksetup -setairportpower airport on")

Thanks to Hackaholic

like image 101
hzleonardo Avatar answered Dec 14 '25 20:12

hzleonardo



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!