iwlist/iwconfig/iw/wpa_supplicant命令及信道可视化


iwlist/iwconfig/iw/wpa_supplicant命令

iwlist

iwlist wlan0 scan[ning]					列出WiFi扫描结果
iwlist wlan0 freq[uency]/channel		列出当前地区可用频率
iwlist wlan0 rate/bit[rate]		 		列出支持的连接速度
iwlist wlan0 keys/enc[ryption]			列出所支持的加密密钥大小
iwlist wlan0 power						列出电源模式
iwlist wlan0 txpower					列出传输功耗
iwlist wlan0 retry						列出重连限制与次数
iwlist wlan0 ap/accesspoint/peers		列出热点信息
iwlist wlan0 event						列出设备支持的无线事件
iwlist wlan0 auth						列出当前设置的WPA认证参数
iwlist wlan0 wpa[keys]					列出设备中设置的所有WPA加密密钥
iwlist wlan0 genie						列出设置的通用信息元素
iwlist wlan0 modu[lation]				列出设备支持的调制和当前启用的调制
iwlist --version						列出版本信息
iwlist --help							列出帮助信息

iwconfig

iwconfig wlan0 freq 2422000000			设置频率
iwconfig wlan0 freq 2.422G				设置频率
iwconfig wlan0 channel 3				设置信道
iwconfig wlan0 channel auto				设置信道
iwconfig wlan0 modu 11g					强制设置调制方式
iwconfig wlan0 modu CCK OFDMa			强制设置调制方式
iwconfig wlan0 modu auto				强制设置调制方式
iwconfig wlan0 txpower 15				设置发射功率为15dBm
iwconfig wlan0 txpower 30mW				设置发射功率:dBm=30+log(W)
iwconfig wlan0 txpower auto				设置自动选择发射功率
iwconfig wlan0 txpower off				关闭发射单元
iwconfig wlan0 sens -80					负数为接收灵敏度下限,低则表信号差,网卡会采取措施
iwconfig wlan0 sens 2					正数表示百分比
iwconfig wlan0 retry 16					设置最大重传次数
iwconfig wlan0 retry lifetime 300m		设置最长重试时间,默认单位为秒
iwconfig wlan0 retry min limit 8		若支持自动模式,min和max指定上下限
iwconfig wlan0 rts 250					设置握手最小包的大小,等于最大值表禁止该机制
iwconfig wlan0 rts off					auto/off/fixed禁止RTS/CTS握手方式
iwconfig wlan0 frag 512					设置发送数据包的分片大小
iwconfig wlan0 frag off					auto/fixed/off允许Burst模式
iwconfig wlan0 power period 2			指定唤醒的周期,默认单位为秒
iwconfig wlan0 power 500m unicast		all/unicast/multicast指定允许唤醒的数据包类型
iwconfig wlan0 power timeout 300u all	all/unicast/multicast指定允许唤醒的数据包类型
iwconfig wlan0 power off				off/on参数指定是否允许电源管理
iwconfig wlan0 power min period 2 power max period 4 指定唤醒的周期

iw

iw --debug												使能netlink调试
iw --version											查看版本信息
iw help													显示帮助信息
iw event [-t] [-r] [-f]									监听内核事件
iw list/phy												列出设备性能
iw dev													列出无线硬件的所有网络接口
iw dev wlan0 scan										搜索周围WiFi信息
iw dev wlan0 link										获得连接状态
iw dev wlan0 info										显示接口信息
iw dev wlan0 station dump								列出所有STA信息
iw dev wlan0 connect wifi名称							连接至OPEN方式的AP
iw dev wlan0 connect wifi名称 2432						有同名热点AP时指定特定频段
iw dev wlan0 connect wifi名称 key 0:密码 d:1:默认密码	连接至WEP加密方式的AP
iw dev wlan0 disconnect									断开连接

wpa_supplicant

wpa_supplicant —— 连接AP热点

前面iwlist、iwconfig属于wireless tools的程序,iw是iwconfig的替代者,都仅支持连接OPEN与WEP加密方式的WiFi;而wpa_supplicant支持在802.11规范中定义的各种安全连接和WPS。

wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf -B

配置文件/etc/wpa_supplicant.conf内容参考:



ctrl_interface=/var/run/wpa_supplicant

network={
 ssid="WiFi-1"
 key_mgmt=NONE



ctrl_interface=/var/run/wpa_supplicant

network={
 ssid="WiFi-1"
 key_mgmt=NONE
 wep_key0="abcde"
 wep_key1=0102030405
 wep_tx_keyidx=0
}

<WPA模式>:

ctrl_interface=/var/run/wpa_supplicant

network={
 ssid="WiFi-1"
 key_mgmt=WPA-PSK
 proto=WPA
 pairwise=TKIP
 group=TKIP
 psk="123123123"
}

<WPA2模式>:

ctrl_interface=/var/run/wpa_supplicant

network={
 ssid="WiFi-1"
 psk="123123123"
}

根据sudo iwlist wlan0 scan可视化并统计数据

sudo iwlist wlan0 scan > 1.txt

进行一点点的数据处理即可获得:

,Frequency:2.432 GHz (Channel 5),Quality=70/70  Signal level=-38 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.412 GHz (Channel 1),Quality=61/70  Signal level=-49 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.412 GHz (Channel 1),Quality=70/70  Signal level=-29 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
,Frequency:2.412 GHz (Channel 1),Quality=65/70  Signal level=-45 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.412 GHz (Channel 1),Quality=65/70  Signal level=-45 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.422 GHz (Channel 3),Quality=67/70  Signal level=-43 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.432 GHz (Channel 5),Quality=70/70  Signal level=-38 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.437 GHz (Channel 6),Quality=68/70  Signal level=-42 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:2.437 GHz (Channel 6),Quality=68/70  Signal level=-42 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:2.437 GHz (Channel 6),Quality=47/70  Signal level=-63 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:2.452 GHz (Channel 9),Quality=68/70  Signal level=-42 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.447 GHz (Channel 8),Quality=70/70  Signal level=-30 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.462 GHz (Channel 11),Quality=65/70  Signal level=-45 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.462 GHz (Channel 11),Quality=64/70  Signal level=-46 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.457 GHz (Channel 10),Quality=70/70  Signal level=-34 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.462 GHz (Channel 11),Quality=39/70  Signal level=-71 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:2.462 GHz (Channel 11),Quality=40/70  Signal level=-70 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:2.462 GHz (Channel 11),Quality=36/70  Signal level=-74 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:2.462 GHz (Channel 11),Quality=67/70  Signal level=-43 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.457 GHz (Channel 10),Quality=70/70  Signal level=-32 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.462 GHz (Channel 11),Quality=65/70  Signal level=-45 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:5.745 GHz (Channel 149),Quality=45/70  Signal level=-65 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.745 GHz (Channel 149),Quality=61/70  Signal level=-49 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.745 GHz (Channel 149),Quality=38/70  Signal level=-72 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.745 GHz (Channel 149),Quality=38/70  Signal level=-72 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.765 GHz (Channel 153),Quality=65/70  Signal level=-45 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.765 GHz (Channel 153),Quality=35/70  Signal level=-75 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.785 GHz (Channel 157),Quality=38/70  Signal level=-72 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.785 GHz (Channel 157),Quality=38/70  Signal level=-72 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.805 GHz (Channel 161),Quality=41/70  Signal level=-69 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.805 GHz (Channel 161),Quality=70/70  Signal level=-39 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:2.412 GHz (Channel 1),Quality=42/70  Signal level=-68 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:2.437 GHz (Channel 6),Quality=46/70  Signal level=-64 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:2.452 GHz (Channel 9),Quality=70/70  Signal level=-39 dBm  ,Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
,Frequency:5.745 GHz (Channel 149),Quality=30/70  Signal level=-80 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.745 GHz (Channel 149),Quality=70/70  Signal level=-37 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.745 GHz (Channel 149),Quality=61/70  Signal level=-49 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
,Frequency:5.785 GHz (Channel 157),Quality=70/70  Signal level=-38 dBm  ,Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s

再进行一点点处理:

['2.432 GHz (Channel 5)', '2.412 GHz (Channel 1)', '2.412 GHz (Channel 1)', '2.412 GHz (Channel 1)', '2.412 GHz (Channel 1)', '2.422 GHz (Channel 3)', '2.432 GHz (Channel 5)', '2.437 GHz (Channel 6)', '2.437 GHz (Channel 6)', '2.437 GHz (Channel 6)', '2.452 GHz (Channel 9)', '2.447 GHz (Channel 8)', '2.462 GHz (Channel 11)', '2.462 GHz (Channel 11)', '2.457 GHz (Channel 10)', '2.462 GHz (Channel 11)', '2.462 GHz (Channel 11)', '2.462 GHz (Channel 11)', '2.462 GHz (Channel 11)', '2.457 GHz (Channel 10)', '2.462 GHz (Channel 11)', '5.745 GHz (Channel 149)', '5.745 GHz (Channel 149)', '5.745 GHz (Channel 149)', '5.745 GHz (Channel 149)', '5.765 GHz (Channel 153)', '5.765 GHz (Channel 153)', '5.785 GHz (Channel 157)', '5.785 GHz (Channel 157)', '5.805 GHz (Channel 161)', '5.805 GHz (Channel 161)', '2.412 GHz (Channel 1)', '2.437 GHz (Channel 6)', '2.452 GHz (Channel 9)', '5.745 GHz (Channel 149)', '5.745 GHz (Channel 149)', '5.745 GHz (Channel 149)', '5.785 GHz (Channel 157)']
['70', '61', '70', '65', '65', '67', '70', '68', '68', '47', '68', '70', '65', '64', '70', '39', '40', '36', '67', '70', '65', '45', '61', '38', '38', '65', '35', '38', '38', '41', '70', '42', '46', '70', '30', '70', '61', '70']
['-38', '-49', '-29', '-45', '-45', '-43', '-38', '-42', '-42', '-63', '-42', '-30', '-45', '-46', '-34', '-71', '-70', '-74', '-43', '-32', '-45', '-65', '-49', '-72', '-72', '-45', '-75', '-72', '-72', '-69', '-39', '-68', '-64', '-39', '-80', '-37', '-49', '-38']
['5', '1', '1', '1', '1', '3', '5', '6', '6', '6', '9', '8', '11', '11', '10', '11', '11', '11', '11', '10', '11', '149', '149', '149', '149', '153', '153', '157', '157', '161', '161', '1', '6', '9', '149', '149', '149', '157']
['1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s', '1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s', '1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s', '1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s', '1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s', '1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s', '1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s', '6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s', '6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s', '6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s', '1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s', '1 Mb/s; 2 Mb/s;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s; 9 Mb/s', '6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s', '6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s', '6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s', '6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s']

动态柱状图

class Quadrotor():
    def __init__(self,labels, quants,x_label='Chnnel',y_label='num',img_title='WIFI_Chnnel',  show_animation=True):

        self.show_animation = show_animation

        if self.show_animation:
            plt.ion()
            fig = plt.figure()
            self.ax = fig.add_subplot(111)

        self.update_pose(labels,quants)

    def update_pose(self, labels,quants):
        self.labels=labels
        self.quants=quants
        if self.show_animation:
            self.draw_bar()


    def draw_bar(self,x_label='Chnnel',y_label='num',img_title='WIFI_Chnnel'):
        width = 0.4
        ind = np.linspace(0.5, 9.5, len(self.labels))
        # make a square figure
        # Bar Plot
        self.ax.bar(ind - width / 2, self.quants, width, color='green')
        # Set the ticks on x-axis
        self.ax.set_xticks(ind)
        self.ax.set_xticklabels(self.labels)
        # labels
        self.ax.set_xlabel(x_label)
        self.ax.set_ylabel(y_label)
        # title
        self.ax.set_title(img_title, bbox={'facecolor': '0.8', 'pad': 5})
        plt.grid(True)
        plt.pause(0.1)

数据解析

iwscanSSIDstr.append(iwscanSSID[i].split("\n")[5].split("                    ")[1] +','+iwscanSSID[i].split("\n")[2].split("                    ")[1]+','+iwscanSSID[i].split("\n")[3].split("                    ")[1]+','+iwscanSSID[i].split("\n")[6].split("                    ")[1]+','+iwscanSSID[i].split("\n")[1].split("                    ")[1])
# print(iwscanSSID[i].split("\n")[5].split("                    ")[1])
# print(iwscanSSID[i].split("\n")[2].split("                    ")[1])
# print(iwscanSSID[i].split("\n")[3].split("                    ")[1])
# print(iwscanSSID[i].split("\n")[6].split("                    ")[1])
SSID.append(iwscanSSIDstr[i-1].split(",")[0][iwscanSSIDstr[i-1].split(",")[0].find(":")+1:len(iwscanSSIDstr[i-1].split(",")[0])])
Chnnel_sign.append(iwscanSSIDstr[i-1].split(",")[1][iwscanSSIDstr[i-1].split(",")[1].find(":")+1:len(iwscanSSIDstr[i-1].split(",")[1])])
Quality.append(iwscanSSIDstr[i-1].split(",")[2][iwscanSSIDstr[i-1].split(",")[2].find("=")+1:iwscanSSIDstr[i-1].split(",")[2].find("/")])
Signal_level.append(iwscanSSIDstr[i-1].split(",")[2][iwscanSSIDstr[i-1].split(",")[2].find("=",10)+1:iwscanSSIDstr[i-1].split(",")[2].find(" dBm")])
channel2.append(iwscanSSIDstr[i-1].split(",")[4][iwscanSSIDstr[i-1].split(",")[4].find(":")+1:len(iwscanSSIDstr[i-1].split(",")[4])])
Bit_Rates.append(iwscanSSIDstr[i-1].split(",")[3][iwscanSSIDstr[i-1].split(",")[3].find(":")+1:len(iwscanSSIDstr[i-1].split(",")[3])])

在树莓派上显示太卡,用tcp发给电脑进行解析

dict1 = {
    "SSID":SSID,
    "Chnnel_sign":Chnnel_sign,
    "Quality":Quality,
    "Signal_level":Signal_level,
    "Bit_Rates":Bit_Rates,
    "channel2":channel2
}

send_one_message(tctimeClient,dict1)
from pickle import dumps, loads
<!-- 通过这个来进行打包发送 -->

将数据进行显示


操作操作,就可以最终实现linux上面的实时检测,不需要tcp,效果更好。
参考:


文章作者: 万鲲鹏
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 万鲲鹏 !
评论
  目录