Linux wireless network selection script

A few people keep looking for scripts that lets them choose which wireless network to connect in to. Since I move between a couple of AP’s at work, plus at home, I knocked this up a few days ago rather than having a script for each network. Is nothing flash, it can’t be with my bash coding skills!

#!/bin/bash
# Wireless network connection script
# Displays easy menu allowing the seletion of prefered network

# 22.11.05 - fouldsy.com

# Change the settings for your own network. This assumes you're using
# static IP addressing and connecting it with encryption enabled.

clear
echo "Please select which wireless you would like to connect to:"
echo " "
echo "1. School wireless network (GCS-WAP-003)"
echo "2. School wireless network (GCS-WAP-004)"
echo "3. Home wireless netork"
echo "4. None, exit this menu"
echo ""
echo "Your choice:"

read character

case $character in
1 ) echo "Connecting in to school wireless network (GCS-WAP-003)"

depmod -a
modprobe ndiswrapper

ifconfig eth0 down
ifconfig wlan0 down

iwconfig wlan0 essid "youressid"
iwconfig wlan0 key restricted [1] yourkey
ifconfig wlan0 youripaddress netmask yournetmask

route add default gw yourdefaultgw

# I also switch to different nameservers depending on the network
# Uncomment the following + adjust if you wish to do the same
# cp /etc/schoolresolv.conf /etc/resolv.conf

ifconfig wlan0 up
;;
2 ) echo "Connecting in to school wireless network (GCS-WAP-004)"

depmod -a
modprobe ndiswrapper

ifconfig eth0 down
ifconfig wlan0 down

iwconfig wlan0 essid "youressid"
iwconfig wlan0 key restricted [1] yourkey
ifconfig wlan0 youripaddress netmask yournetmask

route add default gw yourdeaultgw

# I also switch to different nameservers depending on the network
# Uncomment the following + adjust if you wish to do the same
# cp /etc/schoolresolv.conf /etc/resolv.conf

ifconfig wlan0 up

;;
3 ) echo "Connecting in to home wireless network"

depmod -a
modprobe ndiswrapper

ifconfig eth0 down
ifconfig wlan0 down

iwconfig wlan0 essid "youressid"
iwconfig wlan0 key restricted [1] yourkey
ifconfig wlan0 youripaddress netmask yournetmask

# I also switch to different nameservers depending on the network
# Uncomment the following + adjust if you wish to do the same
# cp /etc/homeresolv.conf /etc/resolv.conf

route add default gw yourdefaultgw

ifconfig wlan0 up
;;
4 ) echo "Okay, no wireless network required. Exiting..."
;;
* ) echo "Please select an option between 1 and 4 to choose a wireless network"
esac

Of course, you can add in additional networks, or remove networks as you see fit. This either needs running as root, or, more elegantly, use sudo to allow normal users to call up this menu and select the network required.

About

Senior Engineer for a St. Louis cloud computing, managed services, and co-location company with a passion for virtualization and server management.

Posted in computing, linux

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About Me
Iain Foulds, 30 years old. Originally from England, now living in St. Louis after 4 years in Alaska. I currently work as a senior engineer for a St. Louis cloud computing, managed services, and co-location company . Very passionate about photography. More...
Categories
Archives