You are not logged in.
Pages: 1
Hey, this is my first script ever!
I wrote a wpa_supplicant helper script, because im always reinstalling arch (trying new WM,DE,etc), so this is the script that i use to get connected to wireless networks easily. This script is better for a fresh install, on a later time is better to use wicd CLI or something like that. Maybe this can be helpful for someone
#!/bin/bash
# Run this script with bash shell
# wpa_supplicant helper script
#ifconfig eth0 down
#ifconfig wlan0 up
clear
ifconfig eth0 down
ifconfig wlan0 up
pkill dhcpcd
GLOBAL=0
ext=n
PASS="1234"
echo "1) Set up new connection (set /etc/wpa_supplicant.conf)"
echo "2) Use actual configuration (/etc/wpa_supplicant.conf)"
echo "3) Exit"
echo -n :; read GLOBAL
if [ $GLOBAL = 1 ]; then
while [ $ext = n ]; do
clear
flag=1
count=$(iwlist scan 2>/dev/null | grep Cell | wc -l)
iwlist scan 2>/dev/null | grep ESSID > buffer.cr
(( count++ ))
while [ $flag -lt $count ]; do
cell=$(iwlist scan 2>/dev/null | grep "Cell 0$flag")
essid=$(sed -n -e "${flag}p" ./buffer.cr)
echo -n "$cell"
echo "$essid"
echo ""
(( flag++ ))
done
rm buffer.cr
echo -n "Which connection use?(essid): "; read essid;
echo -n "Password: "; read PASS;
clear
echo "Connection Data:"
echo ESSID: $essid
echo Password: $PASS
echo -n "Is this correct?(y/n):"; read ext
if [ $ext = y ]; then
wpa_passphrase $essid "$PASS" > /etc/wpa_supplicant.conf
GLOBAL=2;
fi
done
ext=n
fi
if [ $GLOBAL = 2 ]; then
wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant.conf
SEL=0
IP=192.168.0.1
GW=192.168.0.1
DNS=192.168.0.1
while [ $ext = n ]; do
echo
echo "Adress type:"
echo "1) DHCP"
echo "2) Static"
echo -n :; read SEL
case $SEL in
1)
dhcpcd wlan0
ext=y
;;
2)
echo
echo -n "IP Adress: "; read IP
echo -n "Gateway: "; read GW
echo -n "Primary DNS: "; read DNS
ifconfig wlan0 $IP
route add default gw $GW
echo "# Generated by wpa_supplicant helper script" > /etc/resolv.conf
echo "# /etc/resolv.conf.head can replace this line" >> /etc/resolv.conf
echo "nameserver $DNS" >> /etc/resolv.conf
echo "# /etc/resolv.conf.tail can replace this line" >> /etc/resolv.conf
ext=y
;;
*)
clear
echo "No adress type specified, try again"
;;
esac
done
echo
echo "DONE!, verify your connection."
exit 0
else
echo
echo "Nothing changed!"
fi
- The script scans nearly networks, so you can choose wich connection do you want to use
- You can you choose to use static or dhcp IP Adresses
- The script set ups /etc/resolv.conf (DNS Servers)
While you're using the script is necessary to introduce the info (essid, password,ip,etc) without quotes.
I hope this helps (someone )
P.S. Needs the packages: wpa_supplicant,wireless_tools
Last edited by AurosGamma (2011-03-23 00:55:02)
Offline
Does this script work with WPA2 too?
Offline
Yeah, it worked for me on wpa and wpa2
Offline
Great!
Running D-Link DWA-140. Picked "wireless_tools" and "netcfg" during install.
Think this script will make this run, DWA-140 is already included in the kernel?
Will try it when I get home from work.
Thanks!
Offline
The script works with any router, that's indifferent.
You should worry about installing your wireless card driver
e.g. My laptop has Intel Wifi link 5100, so i installed:
iw
iw_5000 (right now i cant remember the real name) that works on my chipset
wireless_tools
Just find whats your chipset and install the proper driver, im sure that you can find all the info on the wiki
P.S. This scripts was made based on the wiki steps, so you shouldn't have any problem
Last edited by AurosGamma (2011-03-22 08:41:15)
Offline
Hi,
Thank you for your helpful script. It is exactly what I was looking for.
If you are still using this script, I'd suggest adding a root user check, as it appears to be a requirement to run properly:
# Root check (Insert at beginning)
if [ 'id -u' -ne 0 ]; then
echo "Error: This script has to be run by root."
exit 2
fi
Offline
Pages: 1