iwlist扫描输出窗体

2024-06-16 11:53:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我得写一个工具来从iwlist扫描中找出加密类型。我只是不知道是否有标准输出。谷歌搜索看起来人们发布的格式略有不同,但我不知道他们是否只是复制/粘贴错误或什么。具体地说,在Encryption key: On中,On/Off第一个字母总是大写吗?那IE: IEEE 802.11i/WPA2 Version 1怎么样?加密总是以IEEE 802.11i/开头吗?在

我希望这可以问在这里。在


Tags: 工具key类型标准粘贴on格式错误
2条回答

由于/proc/net/wireless只是显示当前WLAN连接的信息,所以我修改了一个脚本来包含必要的加密信息,例如feed 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 )

脚本输出(示例):

^{pr2}$

如果SSID有多个可用的加密机制,则它们用"|"分隔。在

解析/proc/net/wireless的内容可能更好,这取决于您需要什么。This将帮助您开始。这些字段都是相同的,但值可能因驱动程序和设备而异。所以,不,你可能不能依赖拼写来保持一致,而大写更不可能。在

相关问题 更多 >