Skip to content

Instantly share code, notes, and snippets.

@cpu
Created March 11, 2014 08:02
Show Gist options
  • Save cpu/9481399 to your computer and use it in GitHub Desktop.
Save cpu/9481399 to your computer and use it in GitHub Desktop.
So you're stuck in an Airport overnight too huh?
#!/usr/bin/python
# Fuck Boingo. Fuck $7 wifi
# requests module is a non-optional dependency
# gntp is an optional dependency for Growl support
from os import sys
from random import randint
from shlex import split
from subprocess import check_call
from threading import Timer
from time import sleep
try:
from requests import post
except ImportError:
sys.exit("Error: script requires python requests module.")
defaultIface = "en0"
defaultDelay = 60 * 21
runCmd = lambda cmd : check_call(split(cmd))
# Use Growl & gntp if available, otherwise fall back to "say"
try:
from gntp import notifier
def alert(msg):
notifier.mini(msg)
except ImportError:
def alert(msg):
runCmd("say '{0}'".format(msg))
# Makes no attempt to generate Manufacturer assigned MAC addresses
def randMAC():
return ":".join([ "{:02X}".format(randint(0,255)) for x in range(0,6) ])
# Works on _my_ OSX Lion machine, YMMV
def setMAC(iface):
runCmd("airport -z")
sleep(2)
runCmd("ifconfig {0} ether {1}".format(iface, randMAC()))
sleep(2)
runCmd("ifconfig {0} down".format(iface))
sleep(2)
runCmd("ifconfig {0} up".format(iface))
sleep(4) #longer sleep to associate again
def regForWifi():
# Need to fix this up to automate the POST with the free wifi login.
# For now, this will open a browser tab to Yahoo that will be caught
# by the boingo captive portal. Log into the free wifi there.
runCmd("open http://yahoo.ca")
def renewWifi(iface):
alert("Renewing wifi")
setMAC(iface)
alert("New MAC set")
regForWifi()
#Set a timer to renew again in defaultDelay seconds
t = Timer(defaultDelay, renewWifi, [ defaultIface ])
alert("Sleeping for {0} minutes".format(defaultDelay / 60))
t.start()
renewWifi(defaultIface)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment