Created
April 3, 2013 00:54
-
-
Save Ceasar/5297593 to your computer and use it in GitHub Desktop.
Connect and stayed connected to AirPennNet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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