Skip to content

Instantly share code, notes, and snippets.

@Ceasar Ceasar/connect.py
Created Feb 20, 2014

Embed
What would you like to do?
import sys
import time
from sh import networksetup
DEVICE = 'en0'
NETWORK = u'AirPennNet'
NETWORK = u'Lovers&Madmen'
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:
print get_network(), NETWORK
while 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
You can’t perform that action at this time.