GRCCwifi

Description: Simple Script To automatically log into Green River Community College's Wifi
Dependencies: python2, python2-mechanize
Download: grccwifi.py
Source Code [Python]:
#! /usr/bin/env python2
"""
This is a simple mechanize script that logs me into GRCC's School Wifi. 

Requires python2-mechanize.
"""
import sys
import cookielib
import mechanize
import string
from time import sleep

# User-Definable Variables Here
LOGIN = 'https://1.1.1.1/login.html'
USER = 'Student ID Goes Here'
PASS = 'Password Goes Here'

# Setup Browser
def getBrowser():
    br = mechanize.Browser()
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)
    br.set_handle_redirect(True)
    br.set_handle_equiv(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)
    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=5)
    br.add_handler(mechanize.HTTPSHandler())
    return br

# Run the actual login
# buttonClicked = 4 is REQUIRED for GRCC
def login(br):
    br.open(LOGIN)
    br.select_form(nr=0)
    br.form.set_all_readonly(False)
    br.form['buttonClicked'] = "4"
    br.form['username'] = USER
    br.form['password'] = PASS
    br.submit()
    
def main():
    # Wait a few seconds to make sure we're connected
    sleep(3)
    # Run the script
    br = getBrowser()
    login(br)

if __name__ == '__main__':
    main()