LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Wireless Networking (https://www.linuxquestions.org/questions/linux-wireless-networking-41/)
-   -   Automatic connection to different hotspots (https://www.linuxquestions.org/questions/linux-wireless-networking-41/automatic-connection-to-different-hotspots-329667/)

quiescere 06-02-2005 02:53 PM

Automatic connection to different hotspots
 
Having finally found a combination of kernel and prism54 versions that works with reliably with my setup (2.6.7 with prism54 1.1 on an old toshiba satellite with a WG511), I'm now happily using my laptop all over town. However, apart from my home network, which I've set up as the default connection, all other networks require me to run through a set of iwconfig/ifconfig/dhcpcd commands manually. Is there a utility that will do this automatically?

I've both kismet and airsnort installed, and they're quite useful, but unless I've overlooked some features they are purely sniffers. I want something that will display a list of ambient networks, allow me to select from the list, and ideally store any relevant connection information (WEP keys, in particular), so I don't have to re-enter them every time I reconnect to a network I've been before.

I can write my own if necessary, but it just seems so obvious a task that someone out there must have done it before (and probably better). O, and in an ideal world, this utility would not depend on KDE or GNOME.

Hangdog42 06-03-2005 04:36 PM

You might want to check out KwifiManager, which does some of what you want. It can store up to four different configurations and despite the K moniker, it runs on pretty much any X desktop. However, it might require a KDE library or two. However, I don't think it scans for new networks.

I got tired of pretty much the same problem, so I wrote a script that stores the info for my home network, but before it configures the card it first scans for available networks and then presents a list to choose from. Since my home network is the only one I use WEP for, it doesn't store keys for other networks, but it wouldn't be hard to modify it to do so. Since I use ndiswrapper, it loads that module, but that would be easy to change to load different modules. It is also written for Slackware, so it may need some tweaking to work with other distros.

Code:

#!/usr/bin/perl
$Interface = "wlan0";
$HomeESSID = "HomeDomainName";
$WEP = "HomeWEPKey";
$Mode = "Managed";
$IWCONFIG = "/sbin/iwconfig";
$DHCP = "/sbin/dhcpcd -t 10 -d";
@APList = ();
#First load the ndiswrapper module
print("Loading ndiswrapper\n");
system("/sbin/modprobe ndiswrapper");
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");
        #&errorCheck('Second Mode');
        system('/sbin/iwconfig wlan0 key $WEP);
        #&errorCheck('WEP');
        print("Requesting IP from $HomeESSID\n");
        system("$DHCP $Interface");
        #&errorCheck('DHCPCD');
        system ("ifconfig $Interface up");
        #&errorCheck('Ifup');
        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 = <STDIN>;
        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;
}



All times are GMT -5. The time now is 10:17 AM.