#!/usr/bin/env python ############################################################################################################# # Python Script which utilises several wireless methods in an easy to understnad HCI # # providing easy connection to a known WPA encrypted wireless network. # # Author: James Ivings Date: 19th March 2009 # # Version: 1.0 # ############################################################################################################# import os import subprocess import sys print "Wireless Connect initializing...\n" while True: print "Make a New Connection? (y/n)" decision=raw_input(">") if decision == "y": print "Enter the network SSID: " ssid=raw_input(">") print "Is the network WPA encryted? Note: wpa-connect does not support any other forms of encryption.(y/n)" decision=raw_input(">") if decision == "y": print "Enter the passphrase for the network: " passphrase=raw_input(">") os.system("/usr/sbin/wpa_passphrase "+ssid+" "+passphrase+" > /WirelessNetworks/"+ssid+".conf") print "SSID and Passphrase saved in /WirelessNetworks/"+ssid+".conf" print "Editing file..." file_in = open("/WirelessNetworks/"+ssid+".conf", "r") allfile = file_in.read() allfile = allfile.replace("psk","#psk") allfile = allfile.replace("##psk", "psk") file_in.close() file_out = open("/WirelessNetworks/"+ssid+".conf", "w") file_out.write(allfile) file_out.close() print "Connecting...\n" try: retcode = subprocess.call("/usr/sbin/wpa_supplicant -Dwext -iwlan0 -c /WirelessNetworks/"+ssid+".conf", shell=True) if retcode < 0: print >>sys.stderr, "Terminated by signal", -retcode else: print >>sys.stderr, "\n\nSomething wasn't right there. Please check your options and try again." os.remove("/WirelessNetworks/"+ssid+".conf") except OSError, e: print >>sys.stderr, "Execution failed:", e #os.system("/usr/sbin/wpa_supplicant -Dwext -iwlan0 -c /WirelessNetworks/"+ssid+".conf") break elif decision == "n": print "Attempting to connect to unsecured network "+ssid+"..." os.system("ifconfig wlan0 up") os.system("iwconfig wlan0 essid "+ssid) os.system("dhcpcd wlan0") break elif decision == "n": print "Use an existing connection? (y/n)" decision=raw_input(">") if decision=="y": print "Configured Networks: " os.system("ls /WirelessNetworks/") print "Enter the config file you would like to use, excluding the .conf extension: " connection=raw_input(">") print "Attempting to connect..." os.system("/usr/sbin/wpa_supplicant -Dwext -iwlan0 -c /WirelessNetworks/"+connection+".conf") print "Done" break elif decision=="n": print "Search for a new connection? (y/n)" decision=raw_input(">") if decision=="y": print "Searching..." os.system("ifconfig wlan0 up") os.system("iwlist scan") print "Would you like to configure a new connection based on these search results? (y/n)" decision=raw_input(">") if decision=="y": print "Make a new Connection..." else: break if decision=="n": print "No further options..." break print "Nothing left to do, exiting.. :)"