专栏名称: 嵌入式微处理器
关注这个时代最火的嵌入式微处理器,你想知道的都在这里。
目录
相关文章推荐
创业家  ·  小赛道,才有大机会 ·  13 小时前  
天津日报  ·  一教授助力茅台增产三到五成?最新回应→ ·  2 天前  
创乎  ·  创业成本:时间与知识的核心作用 ·  2 天前  
南宁晚报  ·  多名主播被抓! ·  3 天前  
南宁晚报  ·  多名主播被抓! ·  3 天前  
51好读  ›  专栏  ›  嵌入式微处理器

Wi-Fi常用工具汇总

嵌入式微处理器  · 公众号  ·  · 2024-04-03 15:58

正文

上一篇文章介绍了 Wi-Fi基础知识 ,今天再给大家详细介绍一下开发过程中 WiFi 常用的开发工具,内容主要介绍工具种类以及基本的使用方法,更多使用可以见后面章节。

1、iwconfig

iwconfig 是一个用于配置和显示无线网络接口参数的命令行工具。它通常与 Linux 下的无线网络设备一起使用,允许用户查看和更改无线网络接口的各种设置。

linux网络(二):无线网络操作- smstars_test - 博客园
# iwconfig --help
Usage: iwconfig [interface]
                interface essid {NNN|any|on|off}
                interface mode {managed|ad-hoc|master|...}
                interface freq N.NNN[k|M|G]
                interface channel N
                interface bit {N[k|M|G]|auto|fixed}
                interface rate {N[k|M|G]|auto|fixed}
                interface enc {NNNN-NNNN|off}
                interface key {NNNN-NNNN|off}
                interface power {period N|timeout N|saving N|off}
                interface nickname NNN
                interface nwid {NN|on|off}
                interface ap {N|off|auto}
                interface txpower {NmW|NdBm|off|auto}
                interface sens N
                interface retry {limit N|lifetime N}
                interface rts {N|auto|fixed|off}
                interface frag {N|auto|fixed|off}
                interface modulation {11g|11a|CCK|OFDMg|...}
                interface commit 
       Check man pages for more details.

常用命令如下

iwconfig wlan0        # 查看wlan0网卡信息
iwconfig wlan0 essid off    # essid配置
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 # 指定唤醒的周期

2、iwlist

iwlist 是一个用于显示无线网络接口附近的网络信息的命令行工具。它可以用于扫描附近的无线网络,并显示它们的详细信息。

# iwlist
Usage: iwlist [interface] scanning [essid NNN] [last]
              [interface] frequency 
              [interface] channel 
              [interface] bitrate 
              [interface] rate 
              [interface] encryption 
              [interface] keys 
              [interface] power 
              [interface] txpower 
              [interface] retry 
              [interface] ap 
              [interface] accesspoints 
              [interface] peers 
              [interface] event 
              [interface] auth 
              [interface] wpakeys 
              [interface] genie 
              [interface] modulation 

基础命令如下

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       # 列出帮助信息

3、iwgetid

iwgetid 是一个用于获取当前连接的无线网络信息的命令行工具。它可以显示当前系统中已连接的无线网络的 SSID(服务集标识符)和接口名称。

# iwgetid -h
Usage iwgetid [OPTIONS] [ifname]
  Options are:
    -a,--ap       Print the access point address
    -c,--channel  Print the current channel
    -f,--freq     Print the current frequency
    -m,--mode     Print the current mode
    -p,--protocol Print the protocol name
    -r,--raw      Format the output as raw value for shell scripts
    -s,--scheme   Format the output as a PCMCIA scheme identifier
    -h,--help     Print this message

常用命令如下

# iwgetid -a    # 获取接入点MAC地址
wlan0     Access Point/Cell: 24:4B:FE:36:E7:68
# iwgetid -c    # 获取接入点当前通道
wlan0     Channel:2
# iwgetid -f    # 查看接入点频率
wlan0     Frequency:2.417 GHz
# iwgetid -m    # 查看网卡当前模式
wlan0     Mode:Managed
# iwgetid -p    # 获取协议
wlan0     Protocol Name:"IEEE 802.11"

4、iw

这个命令好多朋友经常不用这么复杂的工具,但是有必要了解。

iw 是一个用于配置和管理无线网络设备的命令行工具。它提供了丰富的功能,包括显示无线网络设备信息、扫描附近的无线网络、配置连接参数等。

# iw
Usage:  iw [options] command
Options:
        --debug         enable netlink debugging
        --version       show version (5.19)
Commands:
        dev  ap stop 
        dev  ap start 
        phy  coalesce show 
        phy  coalesce disable 
        phy  coalesce enable 
        dev  auth   <type:open|shared> in MHz> [key 0:abcde d:1:6162636465]
        dev  connect [-w]  [in MHz>] [] [auth open|shared] [key 0:abcde d:1:6162636465] [mfp:req/opt/no]
        dev  disconnect
        dev  cqm rssi  []
        event [-t|-T|-r] [-f]
        dev  ftm start_responder [lci=in hex>] [civic=in hex>]
        dev  ftm get_stats 
        phy  hwsim wakequeues 
        phy  hwsim stopqueues 
        phy  hwsim setps 
        phy  hwsim getps 
        dev  ibss join  in MHz> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [fixed-freq] [] [beacon-interval ] [basic-rates in Mbps,rate2,...>] [mcast-rate in Mbps>] [key d:0:abcde]
        dev  ibss leave
        features 
        commands
        phy
        list
        phy  info
        dev  switch channel  [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons ] [block-tx]
        dev  switch freq  [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons ] [block-tx]
        dev  switch freq  [5|10|20|40|80|80+80|160] [ []] [beacons ] [block-tx]
        dev
        dev  info
        dev  del
        dev  interface add  type <type> [mesh_id ] [4addr on|off] [flags *] [addr ]
        phy  interface add  type <type> [mesh_id ] [4addr on|off] [flags *] [addr ]
        help [command]
        dev  link
        dev  measurement ftm_request  [timeout=] [randomise[=/]]
        dev  mesh_param dump 
        dev  mesh leave
        
        ......

常用命令如下

iw dev       # 显示无线网络设备信息
iw dev wlan0 info    # 显示指定无线网络设备的详细信息
iw dev wlan0 scan    # 扫描周围热点信息
iw dev wlan0 link    # 获得连接状态
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   # 断开连接
iw phy        # 显示无线设备的物理特性和功能
iw phy phy0 info       # 显示支持的无线标准
iw phy phy0 wowlan show   # 查看wowlan状态
iw phy phy0 wowlan enable  # 使能wowlan,漫游功能需要

更多干货可见:高级工程师聚集地,助力大家更上一层楼!

5、wpa_supplicant

wpa_supplicant 是一个用于管理无线网络连接的工具,并且可以支持多种认证和加密方法,如 WPA WPA2 WEP 等,能够处理各种复杂的无线网络场景。

wpa supplicant 2.10 arrives solving some vulnerabilities, integrating  improvements and more | From Linux
# wpa_supplicant -h
wpa_supplicant v2.11-devel-1.0
Copyright (c) 2003-2022, Jouni Malinen  and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.

usage:
  wpa_supplicant [-BddhKLqqstvW] [-P] [-g] \
        [-G] \
        -i -c [-C] [-D] [-H] [-p] \
        [-b] [-e] \
        [-o] [-O] \
        [-N -i -c [-C] [-D] \
        [-m] \
        [-p] [-b] [-I] ...]

drivers:
  nl80211 = Linux nl80211/cfg80211
options:
  -b = optional bridge interface name
  -B = run daemon in  the background
  -c = Configuration file
  -C = ctrl_interface parameter (only used if -c is not)
  -d = increase debugging verbosity (-dd even more)
  -D = driver name (can be multiple drivers: nl80211,wext)
  -e = entropy file
  -g = global ctrl_interface
  -G = global ctrl_interface group
  -h = show this help text
  -H = connect to a hostapd instance to manage state changes
  -i = interface name
  -I = additional configuration file
  -K = include keys (passwords, etc.) in debug output
  -L = show license (BSD)
  -m = Configuration file for the P2P Device interface
  -N = start describing new interface
  -o = override driver parameter for new interfaces
  -O = override ctrl_interface parameter for new interfaces
  -p = driver parameters
  -P = PID file
  -q = decrease debugging verbosity (-qq even less)
  -s = log output to syslog instead of stdout
  -t = include timestamp in debug messages
  -v = show version
  -W = wait for a control interface monitor before starting
example:
  wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf

常用命令如下

wpa_supplicant -iwlan0 -Dnl80211 -B -c/tmp/wpa_supplicant.conf  # 联网配置,conf为具体的配置信息
                # -i设置网卡接口,-D设置驱动名,-B设置后台进行,-c添加配置文件

6、wpa_cli

wpa_cli 是一个用于与 wpa_supplicant 通信的命令行工具。它允许用户通过命令行界面与正在运行的 wpa_supplicant 进程进行交互,以管理无线网络连接、配置网络参数等。

wpa_cli 需要运行在 wpa_supplicant 服务之上,通信方式有两种,一种是进入到新的命令行窗口,交互式输入;一种是直接命令输入并及时返回

交互式

# wpa_cli    # 单独输入该命令,进入新的交互窗口

wpa_cli v2.9
Copyright (c) 2004-2019, Jouni Malinen  and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.


Selected interface 'wlan0'

Interactive mode


help     # 输入help可以查看所有支持的命令  
commands:
  status [verbose] = get current WPA/EAPOL/EAP status
  ifname = get current interface name
  ping = pings wpa_supplicant
  relog = re-open log-file (allow rolling logs)
  note  = add a note to wpa_supplicant debug log
  mib = get MIB variables (dot1x, dot11)
  help [command] = show usage help
  interface [ifname] = show interfaces/select interface

命令格式

wpa_cli help           # 打印帮助信息
wpa_cli -i wlan0 status         # 显示当前连接信息
wpa_cli -i wlan0 scan         # 搜索周围WiFi信息
wpa_cli -i wlan0 scan_result       # 显示上一次的搜索结果
wpa_cli -i wlan0 list_networks       # 显示已配置的网络与信息
wpa_cli -i wlan0 add_network       # 添加一个网络返回一个数字n
wpa_cli -i wlan0 set_network n ssid '"name"'   # 输入要连接的WiFi名称
wpa_cli -i wlan0 set_network n key_mgmt NONE   # 输入加密方式OPEN/WEP
wpa_cli -i wlan0 set_network n wep_key0 '"psk"'   # 输入加密方式WEP的密码
wpa_cli -i wlan0 set_network n psk '"psk"'    # 输入加密方式WPA/WPA2的密码
wpa_cli -i wlan0 enable_network n      # 设置后需要启用WiFi
wpa_cli -i wlan0 save_config       # 保存WiFi配置
wpa_cli -i wlan0 select_network n      # 有多个WiFi时选择其中一个
wpa_cli -i wlan0 reconfigure       # 重新加载配置文件
wpa_cli -i wlan0 disconnect        # 断开WiFi连接
wpa_cli -i wlan0 reconnect        # 重新连接
wpa_cli -i wlan0 remove_network n      # 移除WiFi配置
wpa_cli -i wlan0 terminate        # 关闭后台服务器程序
wpa_cli [-i wlan0          # 进入交互模式,命令可以为status等

7、udhcpc

udhcpc 是一个用于在 Linux 系统上获取 IP 地址的简单 DHCP (动态主机配置协议)客户端工具。它通常用于嵌入式系统或者启动过程中获取网络配置。

以下是 udhcpc 工具的主要功能和用法:

# udhcpc -h
udhcpc: option requires an argument -- 'h'
BusyBox v1.31.1 (2023-11-09 11:00:52 CST) multi-call binary.

Usage: udhcpc [-fbqRB] [-a[MSEC]] [-t N] [-T SEC] [-A SEC/-n]
        [-i IFACE] [-s PROG] [-p PIDFILE]
        [-oC] [-r IP] [-V VENDOR] [-F NAME] [-x OPT:VAL]... [-O OPT]...

        -i IFACE        Interface to use (default eth0)
        -s PROG         Run PROG at DHCP events (default /usr/share/udhcpc/default.script)
        -p FILE         Create pidfile
        -B              Request broadcast replies
        -t N            Send up to N discover packets (default 3)
        -T SEC          Pause between packets (default 3)
        -A SEC          Wait if lease is not obtained (default 20)
        -b              Background if lease is not obtained
        -n              Exit if lease is not obtained
        -q              Exit after obtaining lease
        -R              Release IP on exit
        -f              Run in foreground
        -S              Log to syslog too
        -a[MSEC]        Validate offered address with ARP ping
        -r IP           Request this IP address
        -o              Don't request any options (unless -O is given)
        -O OPT          Request option OPT from server (cumulative)
        -x OPT:VAL      Include option OPT in sent packets (cumulative)
                        Examples of string, numeric, and hex byte opts:
                        -x hostname:bbox - option 12
                        -x lease:3600 - option 51 (lease time)
                        -x 0x3d:0100BEEFC0FFEE - option 61 (client id)
                        -x 14:'
"dumpfile"' - option 14 (shell-quoted)
        -F NAME         Ask server to update DNS mapping for NAME
        -V VENDOR       Vendor identifier (default '
udhcp VERSION')
        -C              Don'
t send MAC as client identifier
Signals:
        USR1    Renew lease
        USR2    Release lease

常用命令如下

udhcpc -iwlan0 -t10 -T2 -A10 -b -s/etc/udhcpc.script  # 分配IP地址
        # -i选择网卡接口 -t发送5个发现报文 -T包间等待5秒 -A未获得租约,等待10S, -s添加分配IP的配置文件

7、hostapd

hostapd 是一个用于在 Linux 系统上实现无线访问点功能的软件。它能够将支持的无线网络接口(如 Wi-Fi 适配器)配置为一个独立的访问点,允许其他设备通过 Wi-Fi 连接到该访问点并访问网络。

# hostapd -h
usage: hostapd [-hdBKtv] [-P ] [-e ] \
         [-g ] [-G ]\
         [-i ]\
         

options:
   -h   show this usage
   -d   show more debug messages (-dd for even more)
   -B   run daemon in the background
   -e   entropy file
   -g   global control interface path
   -G   group for control interfaces
   -P   PID file
   -K   include key data in debug messages
   -i   list of interface names to use
   -s   log output to syslog instead of stdout
   -S   start all the interfaces synchronously
   -t   include timestamps in some debug messages
   -v   show hostapd version

常用命令如下

hostapd -B /tmp/hostapd.conf   # 开启热点
        # -B后台运行 后面是我们的配置文件  hostapd.conf为AP热点设置的信息

8、hostapd_cli

hostapd_cli wpa_cli 一样,都属于客户端, hostapd_cli 依赖于 hostapd 服务,需要在后台运行。

hostapd_cli hostapd 的命令行接口工具,用于与运行中的 hostapd 进程进行交互。通过 hostapd_cli ,用户可以实时监控和配置 hostapd 的运行状态,以及对无线访问点进行管理。







请到「今天看啥」查看全文