mala::home Davide “+mala” Eynard’s website

27Nov/060

Perl Hacks: ESSID-dependant networking startup

Problem: you have a laptop, which has to work with different wifi networks. For each one, you need different startup options (ie. you have to start openvpn at work, you have to set encryption at home, you just have to run networking in all other cases). You would like to autodetect the network you're in and run configs accordingly.

Solution: instead of the usual networking startup script, run this one. Then create some scripts inside /etc/nw directory, one for each ESSID network you've specified inside the Perl script and a default one. For instance:

/etc/nw/wlanHOME:

#!/bin/sh
iwconfig eth1 essid wlanHOME
iwconfig eth1 key 917AD823B4EA3395E214BC258B
/etc/init.d/networking start

/etc/nw/wlanWORK:

#!/bin/sh
/etc/init.d/networking start
/etc/init.d/openvpn start

/etc/nw/default:

#!/bin/sh
/etc/init.d/networking start

... of course it's not perfect, but it's quite easy to understand and I hope that with the code under your hands you'll be able to create something useful.

Have phun,

+mala

Filed under: hacks, perl Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.