Contributed by merdely on from the wifi-value-meal dept.
D. Adam Karim shares his solution to using multiple wireless networks:
Having to jump to various wireless network all the time, I have been forced to come up with a way to keep track of them all and make it as seamless as possible to use one or another. The other feature that I wanted was to be able to keep the base files unchanged as much as possible.
Basically, what I have done was create two files, /etc/rc.wireless and /etc/rc.wireless.conf. These two files handle setting up a hostname.if(5) files for the given device based on the configuration in /etc/rc.wireless.conf. One must also add just a small bit to /etc/netstart in order to get it started.
Here is the diff for /etc/netstart as well as the two files:
--- /usr/src/etc/netstart Wed Aug 1 21:21:27 2007 +++ /etc/netstart Thu Dec 20 15:22:18 2007 @@ -2,6 +2,11 @@ # # $OpenBSD: netstart,v 1.116 2007/08/02 03:19:10 david Exp $ +# Create hostname.if(5) file for wireless device. +if [ -f /etc/rc.wireless ]; then + . /etc/rc.wireless +fi + # Strip comments (and leading/trailing whitespace if IFS is set) # from a file and spew to stdout stripcom() {
/etc/rc.wireless:
#!/bin/sh CONF="/etc/rc.wireless.conf" IFNAME=`sed -ne 's/IFNAME=\"\(.*\)\"/\1/p' ${CONF}` HFILE="/etc/hostname.${IFNAME}" TFILE=`mktemp` OUTPUT="dhcp NONE NONE NONE " rm -f ${HFILE} ifconfig -M ${IFNAME} | sed -ne 's/.*\(..:..:..:..:..:..\).*/\1/p' | \ while read MAC; do if [ -r ${CONF} ]; then . ${CONF} else exit 1 fi if [ $? = 0 ]; then if [ -n "${NWID}" ]; then OUTPUT="${OUTPUT} nwid ${NWID}" fi if [ -n "${BSSID}" ]; then OUTPUT="${OUTPUT} bssid ${BSSID}" fi if [ -n "${NWKEY}" ]; then OUTPUT="${OUTPUT} nwkey ${NWKEY}" fi echo ${OUTPUT} >> ${TFILE} break fi done if [ -s ${TFILE} ]; then cp ${TFILE} ${HFILE} fi rm -f ${TFILE}
/etc/rc.wireless.conf:
#!/bin/sh # wireless configuration IFNAME="iwi0" case "${MAC}" in 00:1a:70:4b:f5:64) NWID="Akarsoft" NWKEY="" ;; 00:e0:98:f4:55:ab) NWID="Karim" NWKEY="somekey" ;; 00:0d:3a:2a:83:7d) NWID="xythos" NWKEY="somekey" BSSID="00:0d:3a:2a:83:7d" ;; 00:01:95:6a:40:2b) NWID="xythos" NWKEY="0xf345ad1293" BSSID="00:01:95:6a:40:2b" ;; 00:06:25:92:53:df) NWID="Lemny" NWKEY="somekey" ;; *) return 1 esac
Don't get me wrong, I don't say that this is perfect but it works for me and thought that others who jump from network to network like I do might enjoy it!
(Comments are closed)
By Anonymous Coward (69.70.68.38) on
Are the dots wildcards?
Comments
By Anonymous Coward (12.158.188.186) on
>
> Are the dots wildcards?
It turns "garbage(FF:FF:FF:FF:FF:FF)garbage" in to "FF:FF:FF:FF:FF:FF". (each "." represents any character in regex)
Comments
By Anonymous Coward (99.235.193.57) on
> >
> > Are the dots wildcards?
>
> It turns "garbage(FF:FF:FF:FF:FF:FF)garbage" in to "FF:FF:FF:FF:FF:FF". (each "." represents any character in regex)
Actually, it turns "garbageFF:FF:FF:FF:FF:FFgarbage" into "FF:FF:FF:FF:FF:FF".
Comments
By Mark Peloquin (incripshin) on
> > >
> > > Are the dots wildcards?
> >
> > It turns "garbage(FF:FF:FF:FF:FF:FF)garbage" in to "FF:FF:FF:FF:FF:FF". (each "." represents any character in regex)
>
> Actually, it turns "garbageFF:FF:FF:FF:FF:FFgarbage" into "FF:FF:FF:FF:FF:FF".
I suppose it has to do with backwards-compatibility. Matching probably wasn't always part of sed.
By D. Adam Karim (Archite) adam@akarsoft.com on
By Anonymous Coward (158.109.1.9) on
Comments
By D. Adam Karim (Archite) on
That's a nice script! The only issue is that it is not automated, which was a big thing for me as I don't want to deal with having to do anything: I want it to just work. I'll most likely keep it around though for when I'm at the local coffee shop though. Thanks for the link!
By Anonymous Coward (76.103.60.14) on
what's that for?
lol.
Comments
By Anonymous Coward (122.49.150.21) on
>
> what's that for?
>
> lol.
For connecting to the network you've just cracked, duh.
Comments
By Anonymous Coward (85.178.80.238) on
> >
> > what's that for?
> >
> > lol.
>
> For connecting to the network you've just cracked, duh.
And what's about WEP(2)? :-p
By Anonymous Coward (71.178.166.14) on
By Anonymous Coward (24.78.165.238) on
Comments
By D. Adam Karim (Archite) on
If your Grandma is running OpenBSD, I'm sure that she has very good knowledge of shells ;)
Anyways, the point of my script would be to make joining the network seamless on startup. If the /etc/rc.wireless.conf file is filled out, then she would not even notice anything and just see her wireless interface requesting an IP address on startup. If no network was around, it would not waste time running DHCP and she'd get to her desktop.
Comments
By Anonymous Coward (199.18.139.74) on
>
> If your Grandma is running OpenBSD, I'm sure that she has very good knowledge of shells ;)
I am a grandmother, I am sexy, and I run OpenBSD, and I know shells. Why don't you call Suzie? She was such a nice girl. I know she'd like to hear from you.
By Anonymous Coward (152.160.24.178) on
My grandmother will be so happy. The real question is why are you trying to satisfy her.