slitaz-tools rev 421
wifibox: use awk to parse scan result
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Jan 22 00:03:18 2010 +0100 (2010-01-22) |
parents | 68ee70163abc |
children | a1963defa12f |
files | tinyutils/wifibox |
line diff
1.1 --- a/tinyutils/wifibox Sat Jan 09 16:01:40 2010 +0000 1.2 +++ b/tinyutils/wifibox Fri Jan 22 00:03:18 2010 +0100 1.3 @@ -4,9 +4,9 @@ 1.4 # Use tabs to indent, split commands from the GUI and use functions. 1.5 # Favorite networks are also supported 1.6 # 1.7 -# (c) 2009 SliTaz GNU/Linux - GNU gpl v3 1.8 +# (c) 2010 SliTaz GNU/Linux - GNU gpl v3 1.9 # 1.10 -VERSION=20090222 1.11 +VERSION=20100118 1.12 1.13 # Export script path and others if needed so we can use them in 'quote'. 1.14 export BIN=$0 1.15 @@ -33,7 +33,9 @@ 1.16 ifconfig $WIFI_INTERFACE up 1.17 for i in `iwlist $WIFI_INTERFACE scan | sed s/"Cell "/Cell-/ | grep "Cell-" | awk '{print $1}'` 1.18 do 1.19 - SCAN=`iwlist $WIFI_INTERFACE scan last | sed s/"Cell "/Cell-/ | grep -A 8 "$i"` 1.20 + SCAN=`iwlist $WIFI_INTERFACE scan last | \ 1.21 + awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \ 1.22 + sed s/"Cell "/Cell-/ | grep -A 5 "$i"` 1.23 ESSID=`echo $SCAN | cut -d '"' -f 2` 1.24 if echo "$SCAN" | grep -q Quality; then 1.25 QUALITY=`echo $SCAN | sed 's/.*Quality=\([^ ]*\).*/\1/' | sed 's/.*Quality:\([^ ]*\).*/\1/'` 1.26 @@ -47,8 +49,8 @@ 1.27 fi 1.28 # Connected or not connected... 1.29 if ifconfig | grep -A 1 $WIFI_INTERFACE | \ 1.30 - grep -q inet && iwconfig $WIFI_INTERFACE | \ 1.31 - grep ESSID | grep -q -w "$ESSID"; then 1.32 + grep -q inet && iwconfig $WIFI_INTERFACE | \ 1.33 + grep ESSID | grep -q -w "$ESSID"; then 1.34 STATUS=connected 1.35 else 1.36 STATUS="-" 1.37 @@ -99,10 +101,11 @@ 1.38 [ -s /var/run/udhcpc.$WIFI_INTERFACE.pid ] && kill `cat /var/run/udhcpc.$WIFI_INTERFACE.pid` 1.39 ifconfig $WIFI_INTERFACE down 1.40 set_rfswitch 1 1.41 - iwconfig $WIFI_INTERFACE txpower auto 1.42 + iwconfig $WIFI_INTERFACE txpower auto 1.43 /etc/init.d/network.sh restart 1.44 # Remove tmp file (could be used to have wireless profiles) 1.45 rm -f /tmp/wifi.conf 1.46 + sleep 2 1.47 } 1.48 1.49 # We must sleep 4 sec to refresh networks list. 1.50 @@ -115,12 +118,12 @@ 1.51 iwconfig $WIFI_INTERFACE txpower off 1.52 set_rfswitch 0 1.53 [ -s /var/run/udhcpc.$WIFI_INTERFACE.pid ] && kill `cat /var/run/udhcpc.$WIFI_INTERFACE.pid` 1.54 - sleep 4 1.55 + sleep 2 1.56 } 1.57 1.58 # Favorite wireless networks use only 3 values: essid. key and type of 1.59 # key 1.60 -FAVORITES_WIFI_list() 1.61 +favorites_wifi_list() 1.62 { 1.63 for i in $FAVORITES_WIFI/*.conf 1.64 do 1.65 @@ -272,7 +275,9 @@ 1.66 # is on we ask for the security key. 1.67 connect_to_essid() 1.68 { 1.69 - SCAN=`iwlist $WIFI_INTERFACE scanning essid "$ESSID_LIST" | grep -A 6 "ESSID"` 1.70 + SCAN=`iwlist $WIFI_INTERFACE scan | \ 1.71 + awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \ 1.72 + grep -B 1 -A 1 "$ESSID_LIST"` 1.73 WIFI_ESSID="$ESSID_LIST" 1.74 ENCRYPTION=`echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/'` 1.75 # Create tmp file used by active_wifi_connexion() 1.76 @@ -355,7 +360,7 @@ 1.77 1.78 <vbox> 1.79 <tree icon=\"network-wireless\"> 1.80 - <width>500</width><height>160</height> 1.81 + <width>520</width><height>160</height> 1.82 <variable>ESSID_LIST</variable> 1.83 <label>ESSID|Quality|Encryption|Status</label> 1.84 <input>$0 detect_wifi_networks</input> 1.85 @@ -367,7 +372,7 @@ 1.86 <action>refresh:WIFI_KEY_TYPE</action> 1.87 </tree> 1.88 <hbox> 1.89 - <text width-chars=\"50\"> 1.90 + <text width-chars=\"54\"> 1.91 <label> 1.92 \"Please double click on a network to connect or enter security key\" 1.93 </label> 1.94 @@ -387,7 +392,7 @@ 1.95 <width>500</width><height>160</height> 1.96 <variable>FAVORITE</variable> 1.97 <label>ESSID|Key Type|Key status</label> 1.98 - <input>$0 FAVORITES_WIFI_list</input> 1.99 + <input>$0 favorites_wifi_list</input> 1.100 <item icon=\"network-wireless\">any | - | -</item> 1.101 <action>$0 favorite_wifi_actions</action> 1.102 <action>refresh:FAVORITE</action> 1.103 @@ -426,7 +431,7 @@ 1.104 </hbox> 1.105 <hbox> 1.106 <text use-markup="true"> 1.107 - <label>"<b>ESSID: </b>"</label> 1.108 + <label>"<b>ESSID: </b>"</label> 1.109 </text> 1.110 <entry> 1.111 <input>. /etc/network.conf; echo "$WIFI_ESSID"</input> 1.112 @@ -435,7 +440,7 @@ 1.113 </hbox> 1.114 <hbox> 1.115 <text use-markup="true"> 1.116 - <label>"<b>Key: </b>"</label> 1.117 + <label>"<b>Key: </b>"</label> 1.118 </text> 1.119 <entry> 1.120 <input>. /etc/network.conf; echo "$WIFI_KEY"</input> 1.121 @@ -470,7 +475,7 @@ 1.122 </hbox> 1.123 <hbox> 1.124 <text use-markup="true"> 1.125 - <label>"<b>Iwconfig args:</b>"</label> 1.126 + <label>"<b>Iwconfig args:</b> "</label> 1.127 </text> 1.128 <entry> 1.129 <input>. /etc/network.conf; echo "$WIFI_IWCONFIG_ARGS"</input> 1.130 @@ -617,7 +622,7 @@ 1.131 1.132 </vbox> 1.133 </window>" 1.134 - gtkdialog --center --program=WIFI_DIALOG >/dev/null 2>&1 1.135 + gtkdialog --center --program=WIFI_DIALOG #>/dev/null 2>&1 1.136 } 1.137 1.138 if [ -n "$1" ]; then