different nwkeys for wifi

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

different nwkeys for wifi

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

Reply | Threaded
Open this post in threaded view
|

Re: different nwkeys for wifi

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

wifi.awk (451 bytes) Download Attachment
attachment1 (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: different nwkeys for wifi

Amit Kulkarni-5
In reply to this post by 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?

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

Reply | Threaded
Open this post in threaded view
|

Re: different nwkeys for wifi

useche
In reply to this post by Jan Stary
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 <[hidden email]> 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