gpt4 book ai didi

bash - 解析 iw wlan0 扫描输出

转载 作者:行者123 更新时间:2023-11-29 08:51:01 26 4
gpt4 key购买 nike

我编写了 wlan 管理器脚本来处理 open/ad-hoc/wep/wpa2 网络。现在我正在尝试解析 iw wlan0 扫描输出,以便为我的脚本获得良好的扫描功能。我的目标是获得这样的输出:

SSID        channel     signal      encryption
wlan-ap 6 70% wpa2-psk
test 1 55% wep

我已经实现的是这样的输出:

$ iw wlan0 scan | grep 'SSID\|freq\|signal\|capability' | tac
SSID: Koti783
signal: -82.00 dBm
capability: ESS Privacy ShortPreamble SpectrumMgmt ShortSlotTime (0x0531)
freq: 2437

我一直在尝试研究 bash/sed/awk,但还没有找到一种方法来实现我正在尝试的目标。那么实现这一目标的好方法是什么?

最佳答案

这是我基于 Sudo_O answer 的最终解决方案:

$1 == "BSS" {
MAC = $2
wifi[MAC]["enc"] = "Open"
}
$1 == "SSID:" {
wifi[MAC]["SSID"] = $2
}
$1 == "freq:" {
wifi[MAC]["freq"] = $NF
}
$1 == "signal:" {
wifi[MAC]["sig"] = $2 " " $3
}
$1 == "WPA:" {
wifi[MAC]["enc"] = "WPA"
}
$1 == "WEP:" {
wifi[MAC]["enc"] = "WEP"
}
END {
printf "%s\t\t%s\t%s\t\t%s\n","SSID","Frequency","Signal","Encryption"

for (w in wifi) {
printf "%s\t\t%s\t\t%s\t%s\n",wifi[w]["SSID"],wifi[w]["freq"],wifi[w]["sig"],wifi[w]["enc"]
}
}'

输出:

$ sudo iw wlan0 scan | awk -f scan.awk
SSID Frequency Signal Encryption
netti 2437 -31.00 dBm Open
Koti783 2437 -84.00 dBm WPA
WLAN-AP 2462 -85.00 dBm WPA

关于bash - 解析 iw wlan0 扫描输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17809912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com