如何获取iw和iwinfo命令输出的所有bssid?这里有iw和iwinfo命令来获取所有ssid。内华达州:
iw dev wlan0 scan 2>/dev/null | awk '
/SSID: / {
if (!seen[$0]++) {
printf "\""
for (i = 2; i <= NF; i++) if (i == 2) printf $i
else printf " " $i
printf "\" "
}
}
'
信息:
iwinfo wlan0 scan | awk '
/ESSID: ".*"/ {
ORS = " "
if (!seen[$0]++) for (i = 2; i <= NF; i++) print $i
}
'
电流AWK输出:
“WiFi-1”“WiFi-2”“WiFi-3”“WiFi-4”“WiFi-5”…
IW控制台输出:
BSS 01:23:45:67:89:AB(on wlan0)
TSF: 128785915910 usec (1d, 11:46:25)
freq: 2437
beacon interval: 200 TUs
capability: ESS ShortPreamble ShortSlotTime (0x0421)
signal: -71.00 dBm
last seen: 990 ms ago
Information elements from Probe Response frame:
SSID: WiFi-1
Supported rates: 1.0* 2.0* 5.5* 6.0 9.0 11.0* 12.0 18.0
DS Parameter set: channel 6
Country: SK Environment: Indoor/Outdoor
Channels [1 - 13] @ 20 dBm
ERP: <no flags>
Extended supported rates: 24.0 36.0 48.0 54.0
WMM: * Parameter version 1
* BE: CW 15-1023, AIFSN 3
* BK: CW 15-1023, AIFSN 7
* VI: CW 7-15, AIFSN 2, TXOP 3008 usec
* VO: CW 3-7, AIFSN 2, TXOP 1504 usec
BSS CD:EF:A0:A1:A2:A3(on wlan0)
TSF: 2381690679244 usec (27d, 13:34:50)
freq: 2467
beacon interval: 200 TUs
capability: ESS ShortPreamble ShortSlotTime (0x0421)
signal: -94.00 dBm
last seen: 90 ms ago
Information elements from Probe Response frame:
SSID: WiFi-2
Supported rates: 1.0* 2.0* 5.5* 6.0 9.0 11.0* 12.0 18.0
DS Parameter set: channel 12
Country: SK Environment: Indoor/Outdoor
Channels [1 - 13] @ 20 dBm
ERP: <no flags>
Extended supported rates: 24.0 36.0 48.0 54.0
WMM: * Parameter version 1
* BE: CW 15-1023, AIFSN 3
* BK: CW 15-1023, AIFSN 7
* VI: CW 7-15, AIFSN 2, TXOP 3008 usec
* VO: CW 3-7, AIFSN 2, TXOP 1504 usec
iwinfo控制台输出:
Cell 01 - Address: 01:23:45:67:89:AB
ESSID: "WiFi-1"
Mode: Master Channel: 11
Signal: -49 dBm Quality: 61/70
Encryption: WPA2 PSK (CCMP)
Cell 02 - Address: CD:EF:A0:A1:A2:A3
ESSID: "WiFi-2"
Mode: Master Channel: 11
Signal: -53 dBm Quality: 57/70
Encryption: WPA2 PSK (CCMP)
我想使用awk获得以下输出:
“01:23:45:67:89:ab”“cd:ef:a0:a1:a2:a3”…
使用awk为两个lib(iw&iwinfo)捕获所有bssid的正确方法是什么?
最佳答案
使用gnu awk使第三个参数匹配():
{ cat iw_output; cat iwinfo_output; } |
awk 'match($0,/([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}/,a) && !seen[a[0]]++{print a[0]}'
01:23:45:67:89:AB
CD:EF:A0:A1:A2:A3
或者获取问题中请求的输出格式:
{ cat iw_output; cat iwinfo_output; } |
awk 'match($0,/([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}/,a) && !seen[a[0]]++{printf "%s\"%s\"", (c++?OFS:""), a[0]} END{print ""}'
"01:23:45:67:89:AB" "CD:EF:A0:A1:A2:A3"
对于其他awk,您将使用
substr($0,RSTART,RLENGTH)
而不是a[0]
。关于linux - 获取所有WiFi的SSID和BSSID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41579598/