2010-09-13 53 views
2

我必須編寫一個工具來從iwlist掃描中獲取加密類型。我似乎無法找到是否有標準輸出。谷歌搜索它看起來像人們發佈略有不同的格式,但我不知道他們是否複製/粘貼錯誤或什麼。具體來說,在Encryption key: On,是On/Off第一個字母總是大寫? IE: IEEE 802.11i/WPA2 Version 1怎麼樣?加密總是以IEEE 802.11i/開頭?iwlist掃描輸出格式

我希望這裏可以問這裏。

回答

1

根據你需要解析/proc/net/wireless的內容,你可能會更好。 This將幫助您入門。這些字段都是相同的,但這些值可能因驅動程序和設備而異。所以不,你可能不能依靠拼寫來保持一致性,而且大寫字母更不是這樣。

1

由於/proc/net/wireless只是顯示有關當前WLAN連接的信息,我修改了一個腳本以包含必要的加密信息。喂wpa_supplicant

#!/bin/bash 
while read line; do 

    ## Reset variables on new network 
    [[ "$line" =~ Cell || "$line" == "" ]] && { 

     # If no WPA encryption info was found though "Encryption" was "On", then we have WEP 
     [[ "$encryption" == "" && "$enc" =~ On ]] && encryption = "WEP" 

     # If we already found one network then echo its information 
     [[ "$network" != "" ]] && echo "$network [$encryption]" 
     network="" 
     encryption="" 
    } 

    ## Test line content and parse as required 
    [[ "$line" =~ Address ]] && mac=${line##*ss: } 
    [[ "$line" =~ \(Channel ]] && { chn=${line##*nel }; chn=${chn:0:$((${#chn}-1))}; } 
    [[ "$line" =~ Frequen ]] && { frq=${line##*ncy:}; frq=${frq%% *}; } 
    [[ "$line" =~ Quality ]] && { 
     qual=${line##*ity=} 
     qual=${qual%% *} 
     lvl=${line##*evel=} 
     lvl=${lvl%% *} 
    } 

    ## Encryption is "On" if WEP or WPA, otherwise it's "Open" 
    [[ "$line" =~ Encrypt ]] && enc=${line##*key:} 
    [[ "$enc" =~ Off ]] && { 
     [[ "$encryption" != "" ]] && encryption="${encryption}," 
     encryption="${encryption}Open" 
    } 

    ## The ESSID is the last line of the basic channel data, so build information string now 
    [[ "$line" =~ ESSID ]] && { 
     essid=${line##*ID:} 
     network="$mac $essid $frq $chn $qual $lvl $enc" # output after ESSID 
    } 

    ## WPA encryption information 
    [[ "$line" =~ WPA ]] && wpa=${line##*WPA} && { 
     [[ "$encryption" != "" ]] && encryption="${encryption}|" 
     encryption="${encryption}WPA$wpa" 
    } 
    [[ "$line" =~ "Group Cipher" ]] && encryption="$encryption,${line##*: }" 
    [[ "$line" =~ "Pairwise Cipher" ]] && encryption="$encryption,${line##*: }" 
    [[ "$line" =~ "Authentication Suites" ]] && encryption="$encryption,${line##*: }" 

done < <(iwlist wlan0 scan 2>/dev/null) 

腳本輸出(示例):

34:81:C7:EB:24:89 "cyberdyne" 2.462 11 67/70 -43 on [WPA2 Version 1,CCMP,CCMP,PSK] 
36:81:C7:EB:24:89 "cyberguest" 2.462 11 65/70 -45 on [WPA2 Version 1,TKIP,CCMP,PSK|WPA Version 1,TKIP,TKIP,PSK] 

如果有可用的SSID然後它們由"|"分隔的多個加密機制。