#!/usr/bin/env python import os import sys interface = "wlan0" essid = "myessid" key = "mykey13charss" channel = "auto" rate = "auto" sleep = 5 def usage(): print """Usage: %s \t-t,--test\tprint out the command that will be executed \t-h,--help\tthis help page""" % sys.argv[0] commands = (\ 'sudo rmmod iwl4965',\ 'sudo rmmod iwlwifi_mac80211',\ 'sudo rmmod cfg80211',\ 'sleep %s' % sleep,\ 'sudo modprobe iwl4965',\ 'sleep %s' % sleep,\ 'sudo ifconfig wlan0 down',\ 'sleep %s' % sleep,\ 'sudo iwconfig %s essid %s channel %s mode ad-hoc key s:%s rate %s' % (interface, essid, channel, key, rate),\ 'sleep %s' % sleep,\ 'sudo ifconfig wlan0 up',\ 'sleep %s' % sleep,\ 'sudo iwconfig %s essid %s channel %s mode ad-hoc key s:%s rate %s' % (interface, essid, channel, key, rate),\ 'sleep %s' % sleep,\ 'sudo dhclient %s' % interface,\ ) test = False for argv in sys.argv: if argv in ("--test","-t"): test = True if argv in ("--help","-h"): usage() sys.exit() for line in commands: if test: print line else: os.system(line) sys.exit(0)