Skip to content

Instantly share code, notes, and snippets.

@Ceasar
Created April 3, 2013 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ceasar/5297593 to your computer and use it in GitHub Desktop.
Save Ceasar/5297593 to your computer and use it in GitHub Desktop.
Connect and stayed connected to AirPennNet.
import sys
import time
from sh import networksetup
DEVICE = 'en0'
NETWORK = u'AirPennNet'
def connect_to_network(network):
networksetup('-setairportnetwork', DEVICE, network)
def get_network():
return networksetup('-getairportnetwork', DEVICE).strip().split()[-1]
def set_wifi_on():
networksetup('-setairportpower', DEVICE, 'on')
def set_wifi_off():
networksetup('-setairportpower', DEVICE, 'off')
def toggle_wifi():
set_wifi_off()
set_wifi_on()
def main():
while True:
while get_network() != NETWORK:
print get_network(), NETWORK
print "toggling wifi..."
toggle_wifi()
print "connecting to %s..." % NETWORK
connect_to_network(NETWORK)
time.sleep(5)
time.sleep(1)
return 0
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment