#!/usr/bin/perl # Set these Variables to your Default: $Interface = "wlan0"; $HomeESSID = "Your_SSID_HERE"; $WEP = "Your_HEX_WEP_Key_Here"; # Managed or Ad-Hoc ? $Mode = "Managed"; $IWCONFIG = "/sbin/iwconfig"; $DHCP = "/sbin/dhcpcd -t 10 -d"; #If you need ndiswrapper, you can uncomment the following two lines: #print("Loading ndiswrapper\n"); #system("/sbin/modprobe ndiswrapper"); ####################################################################### # No configuration beyond this point needed # ####################################################################### @APList = (); print("Scanning for wireless access points\n"); @ScanList = qx/iwlist wlan0 scan/; foreach $a (@ScanList){ if($a =~m/No scan results/){ print("No networks detected, enabling home network\n"); &homeNet; } if($a =~ m/$HomeESSID/){ print("Home network detected\n"); &homeNet; } if ($a =~m/ESSID/){ @Temp = split(/"/,$a); push(@APList,$Temp[1]); for($x=0;$x<=$#APList;$x++){ print("At $x is $APList[$x]\n"); } } } &selectFrom; sub homeNet{ print("Setting up wlan0\n"); system("$IWCONFIG $Interface essid $HomeESSID"); system("$IWCONFIG $Interface mode $Mode"); system('/sbin/iwconfig wlan0 key $WEP'); print("Requesting IP from $HomeESSID\n"); system("$DHCP $Interface"); system ("ifconfig $Interface up"); print("Configuration done\n"); exit; } sub selectFrom{ print("Select one of the following AP points\n"); for($x=0;$x<=$#APList;$x++){ print("$x - $APList[$x]\n"); } print("Select by number: "); $SelectAP = ; if((0 <= $SelectAP) and ($SelectAP<=$#APList)){ print("Using $APList[$SelectAP]\n"); system("$IWCONFIG $Interface essid $APList[$SelectAP]"); print("Requesting IP from $APList[$SelectAP]"); system("$DHCP $Interface"); system("ifconfig $Interface up"); exit; } else{ print("Please select an acceptable number\n"); &selectFrom; } exit; }