I use the following perl script below. I saved it in /etc/rc.wireless
and apply the following patch:
--- netstart Fri Jul 8 15:34:09 2011
+++ /etc/netstart Sun Jul 10 11:43:20 2011
@@ -255,6 +255,8 @@
ip6kernel=NO
fi
+#wifi
+/etc/rc.wireless
# Configure all the non-loopback interfaces which we know about, but
# do not start interfaces which must be delayed. Refer to hostname.if(5)
Good luck!
Luis.
#!/usr/bin/perl -w
# TODO
# 1. Connect to ethernet if available instead.
# 2. Retry if the network was not found.
use strict;
my $nwif = "iwn0";
my $profiles = {
"wpanet" => {psk => "passwordwpa", proto => "wpa" },
"noencrypt" => {},
"wepnet" => {psk =>"passwordwep", proto => "wep"},
};
sub conf_nw {
my $nwid = shift;
my $conf = $profiles->{$nwid};
my $psk_str = $conf->{psk};
if($psk_str) {
my $proto = lc $conf->{proto};
if($proto eq "wep") {
$psk_str = "nwkey \"$psk_str\"";
} elsif($proto eq "wpa") {
$psk_str = "wpakey \"$psk_str\"";
} else {
die "Only \"wep\" and \"wpa\" supported.";
}
} else {
$psk_str = "-wpakey -nwkey";
}
# finally write in hostname.if
open HOSTNAME, ">/etc/hostname.$nwif" or die "Couldn't open hostname.if
file.";
print HOSTNAME "# THIS IS A TEMPORAL FILE.\n# MAKE THE MODIFICATION
IN /etc/rc.wireless.\n";
print HOSTNAME "dhcp nwid \"$nwid\" $psk_str\n";
close HOSTNAME;
}
print "Configuring wifi $nwif... ";
my $nwid = "no known net";
# scanning available networks
open FD, "ifconfig $nwif scan|" or die "where'd ifconfig go?";
while(<FD>) {
if(/^\s*nwid "?(.*?)"? chan/) {
if($profiles->{$1}) {
conf_nw $1;
$nwid = $1;
last;
}
}
}
print "$nwid detected\n";
On Sun, Jul 10, 2011 at 12:51 PM, Jan Stary <[email protected]> wrote:
> Scenario: I am moving my laptop between different wifi networks
> (obviously). Some of these networks are encrypted with WEP, using
> various nwkeys.
>
> What would be an elegant way to remember the various networks' settings
> and choose the one I am connecting to at netstart(8) time? Before I start
> symlinking /etc/rc/hostname.run0.whatever in my rc.local, what existing
> solutions do people use?
>
> Thank yuo for your time
>
> Jan