different nwkeys for wifi

2011-07-10 Thread Jan Stary
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



Re: different nwkeys for wifi

2011-07-10 Thread Gregor Best
I use a simple AWK script which parses the available networks as
returned by ifconfig wpi0 scan and selects the first known one it finds.
It then creates an /etc/hostname.wpi0 for that network and runs
/etc/netstart wpi0. I attached it for reference, though I think it's
extremely easy to rebuild from scratch.

-- 
Gregor Best
#!/usr/bin/awk -f

BEGIN {
conf[essid0] = wpakey foobar\ndhcp;
conf[essid1] = -wpakey\ndhcp;

device = wpi0;
}

/^[[:space:]]+nwid/ {
sub(^[[:space:]]+nwid , )
sub( chan [[:digit:]]+ bssid.+, )
if ($0 in conf) {
print Using configuration for ESSID $0
print up\nnwid $0\nconf[$0] (/etc/hostname.device)
system(sh /etc/netstart device)
exit
}
}


pgpR0l9QtVop0.pgp
Description: PGP signature


Re: different nwkeys for wifi

2011-07-10 Thread Amit Kulkarni
 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?

tedu@ posted a perl script on misc@ about a year or so ago.
HTH



Re: different nwkeys for wifi

2011-07-10 Thread Luis Useche
I use the following perl script below. I saved it in /etc/rc.wireless
and apply the following patch:

--- netstartFri 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 h...@stare.cz 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