diff options
| author | makefu <github@syntax-fehler.de> | 2013-05-25 22:48:24 +0200 | 
|---|---|---|
| committer | makefu <github@syntax-fehler.de> | 2013-05-25 22:48:53 +0200 | 
| commit | 4fa3206a16921d0a7984b0dcd5ca9086786a31cf (patch) | |
| tree | 3716d214e5c8fefb91b361e7cc55d94c86957fa6 /usr/lib/autowifi/lib/iwlist | |
| parent | ed73fba46289f4af60422b2d267ba40834ca97ca (diff) | |
refactor functions for reusability
Diffstat (limited to 'usr/lib/autowifi/lib/iwlist')
| -rw-r--r-- | usr/lib/autowifi/lib/iwlist | 55 | 
1 files changed, 55 insertions, 0 deletions
| diff --git a/usr/lib/autowifi/lib/iwlist b/usr/lib/autowifi/lib/iwlist new file mode 100644 index 00000000..a9f77f0c --- /dev/null +++ b/usr/lib/autowifi/lib/iwlist @@ -0,0 +1,55 @@ +#!/bin/sh + +print_iwlist_env(){ +    # takes environment: +    #   count +    #   MAC +    #   CHANNEL +    #   QUALITY +    #   ENCRYPTION +    #   ESSID +    #   WPA +    #   WPA2 +    for i in ESSID MAC CHANNEL QUALITY ENCRYPTION WPA WPA2;do +        eval echo ${i}_${count}=\$${i} +    done +} + +iwlist_scan(){ +    # usage: iwlist_scan $wifi-itf +    ifconfig $wifi up + +    count=0 +     +    iwlist ${1:-} scan  2>/dev/null | ( while read line; +    do +        case "$line" in +            *"Cell "*) +                [ $count -eq  0 ] || print_iwlist_env +                WPA=0 +                WPA2=0 +                : $((count+=1)) +                MAC="${line#*Address: }" +                ;; +            *Channel:*) +                CHANNEL="${line#*:}" +                ;; +            *Quality=*) +                QUALITY="`printf '%s' ${line#*Quality=} | cut -d/  -f 1`" +                ;; +            *"Encryption key:"*) +                ENCRYPTION="${line#*key:}" +                ;; +            *ESSID:*) +                ESSID="${line#*ESSID:}" +                ;; +            *"IE: IEEE 802.11i/WPA2"*) +                WPA2=1 +                ;; +            *"IE: WPA Version 1"*) +                WPA=1 +                ;; +            *);; +        esac +    done; print_iwlist_env ;echo WIFI_COUNT=$count) +} | 
