The ifconfig, iwconfig, and route commands must be run as root. Hence, a check for the root user is performed before performing any actions in the scripts.
Wireless LAN requires parameters such as essid, key, and frequency to connect to the network. essid is the name of the wireless network to connect to. Some networks use a WEP key for authentication, which is usually a five- or ten-letter hex passphrase. The frequency assigned to the network is required by the iwconfig command to attach the wireless card with the proper wireless network.
The iwlist utility will scan and list the available wireless networks:
# iwlist scan
wlan0 Scan completed :
Cell 01 - Address: 00:12:17:7B:1C:65
Channel:11
Frequency:2.462 GHz (Channel 11)
Quality=33/70 Signal level=-77 dBm
Encryption key:on
ESSID:"model-2"
The Frequency parameter can be extracted from the scan result, from the Frequency:2.462 GHz (Channel 11) line.
WEP is used in this example for simplicity. Note that WEP is insecure. If you are administering the wireless network, use a variant of Wi-Fi Protected Access2 (WPA2).