【WiFi开发全攻略】WIFI常用工具汇总

【WiFi开发全攻略】WIFI常用工具汇总

本节主要介绍我们开发过程中,WiFi常用的开发工具,内容主要介绍工具种类以及基本的使用方法,更多使用可以见后面章节。

1、iwconfig

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

复制代码
# 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 <devname> ap stop 
       dev <devname> ap start 
       phy <phyname> coalesce show 
       phy <phyname> coalesce disable 
       phy <phyname> coalesce enable <config-file>
       dev <devname> auth <SSID> <bssid> <type:open|shared> <freq in MHz> [key 0:abcde d:1:6162636465]
       dev <devname> connect [-w] <SSID> [<freq in MHz>] [<bssid>] [auth open|shared] [key 0:abcde d:1:6162636465] [mfp:req/opt/no]
       dev <devname> disconnect
       dev <devname> cqm rssi <threshold|off> [<hysteresis>]
       event [-t|-T|-r] [-f]
       dev <devname> ftm start_responder [lci=<lci buffer in hex>] [civic=<civic buffer in hex>]
       dev <devname> ftm get_stats 
       phy <phyname> hwsim wakequeues 
       phy <phyname> hwsim stopqueues 
       phy <phyname> hwsim setps <value>
       phy <phyname> hwsim getps 
       dev <devname> ibss join <SSID> <freq in MHz> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>] [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] [key d:0:abcde]
       dev <devname> ibss leave
       features 
       commands
       phy
       list
       phy <phyname> info
       dev <devname> switch channel <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons <count>] [block-tx]
       dev <devname> switch freq <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons <count>] [block-tx]
       dev <devname> switch freq <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]] [beacons <count>] [block-tx]
       dev
       dev <devname> info
       dev <devname> del
       dev <devname> interface add <name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] [addr <mac-addr>]
       phy <phyname> interface add <name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] [addr <mac-addr>]
       help [command]
       dev <devname> link
       dev <devname> measurement ftm_request <config-file> [timeout=<seconds>] [randomise[=<addr>/<mask>]]
       dev <devname> mesh_param dump 
       dev <devname> 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 是一个用于管理无线网络连接的工具,并且可以支持多种认证和加密方法,如WPAWPA2WEP等,能够处理各种复杂的无线网络场景。

复制代码
# wpa_supplicant -h
wpa_supplicant v2.11-devel-1.0
Copyright (c) 2003-2022, Jouni Malinen <j@w1.fi> and contributors
​
This software may be distributed under the terms of the BSD license.
See README for more details.
​
usage:
 wpa_supplicant [-BddhKLqqstvW] [-P<pid file>] [-g<global ctrl>] \
       [-G<group>] \
        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>] [-p<driver_param>] \
       [-b<br_ifname>] [-e<entropy file>] \
       [-o<override driver>] [-O<override ctrl>] \
       [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \
       [-m<P2P Device config file>] \
       [-p<driver_param>] [-b<br_ifname>] [-I<config file>] ...]
​
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 <j@w1.fi> 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 <text> = 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 <PID file>] [-e <entropy file>] \
         [-g <global ctrl_iface>] [-G <group>]\
         [-i <comma-separated list of interface names>]\
         <configuration file(s)>
​
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_cliwpa_cli一样,都属于客户端,hostapd_cli依赖于hostapd服务,需要在后台运行。

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

复制代码
# hostapd_cli -h
usage: hostapd_cli [-p<path>] [-i<ifname>] [-hvBr] [-a<path>] \
                   [-P<pid file>] [-G<ping interval>] [command..]
​
Options:
   -h           help (show this usage text)
   -v           shown version information
   -p<path>     path to find control sockets (default: /var/run/hostapd)
   -s<dir_path> dir path to open client sockets (default: /var/run/hostapd)
   -a<file>     run in daemon mode executing the action file based on events
               from hostapd
   -r           try to reconnect when client socket is disconnected.
               This is useful only when used with -a.
   -B           run a daemon in the background
   -i<ifname>   Interface to listen on (default: first interface found in the
               socket path)
                
commands:
  ping = pings hostapd
 mib = get MIB variables (dot1x, dot11, radius)
 relog = reload/truncate debug log output file
 close_log = disable debug log output file
 status = show interface status info
 sta <addr> = get MIB variables for one station
 all_sta = get MIB variables for all stations
 list_sta = list all stations
 new_sta <addr> = add a new station
 deauthenticate <addr> = deauthenticate a station
 disassociate <addr> = disassociate a station
 ...

常用命令如下

复制代码
hostapd_cli -h                # 显示帮助信息
hostapd_cli -v         # 显示版本信息
hostapd_cli -p <path>       # 指定socket的路径      
hostapd_cli -i wlan0 all_sta     # 显示所有连接设备
hostapd_cli -i wlan0 sta <addr>     # 查看某个设备信息
hostapd_cli -i wlan0 interface     # 显示网卡接口
hostapd_cli -i wlan0 interface [ifname]   # 指定网卡接口
hostapd_cli -i wlan0 get_config     # 获得配置
hostapd_cli -i wlan0 disassociate <addr>  # 断开某个设备的连接
hostapd_cli -i wlan0 level n     # 设置打印级别
hostapd_cli -i wlan0 license     # 显示证书
hostapd_cli [-i wlan0]       # 进入交互模式,命令可以为all_sta等

9、udhcpd

udhcpd 是一个用于在 Linux 系统上提供 DHCP 服务的小型 DHCP 服务器软件。它是 udhcp软件包的一部分,通常用于嵌入式系统或者小型网络环境中。

复制代码
# udhcpd --help
BusyBox v1.31.1 (2023-11-09 11:00:52 CST) multi-call binary.
​
Usage: udhcpd [-fS] [-I ADDR] [CONFFILE]
​
DHCP server
​
        -f     Run in foreground
        -S     Log to syslog too
        -I ADDR Local address
        -a MSEC Timeout for ARP ping (default 2000)
Signals:
       USR1   Update lease file

常用命令如下

复制代码
udhcpd -f /tmp/udhcpd.conf
    # -f运行在前台 /tmp/udhcpd.conf 为IP分配相关的配置

更多文章,可关·注·公·号:【嵌入式艺术】,同时也为大家准备了学习福利,可免费领取。

10、总结

以上,简单介绍了一下WiFi开发过程中经常使用到的工具,并简单介绍了其相关用法,其中包括:

  • iwconfig

  • iwlist

  • iwgetid

  • iw

  • wpa_supplicant

  • wpa_cli

  • udhcpc

  • hostapd

  • hostapd_cli

  • udhcpd

当然一些特定的工具并没有详细介绍,后面我们在慢慢道来。

相关推荐
有续技术6 分钟前
工厂常用软件系统大全中英文全称对照表及功能介绍应用场景ERP MES WMS SCADA IOT SAP等软件系统介绍
物联网
CSND7402 小时前
Ubuntu vi(vim)编辑器配置一键补全main函数
linux·c语言·ubuntu·编辑器·vim
シ風箏5 小时前
Neo4j【环境部署 02】图形数据库Neo4j在Linux系统ARM架构下的安装使用
linux·数据库·arm·neo4j
Cachel wood7 小时前
Vue.js前端框架教程8:Vue消息提示ElMessage和ElMessageBox
linux·前端·javascript·vue.js·前端框架·ecmascript
小屁不止是运维9 小时前
麒麟操作系统服务架构保姆级教程(二)ssh远程连接
linux·运维·服务器·学习·架构·ssh
超爱吃士力架10 小时前
Ubuntu操作系统安装docker
linux·前端·后端
黑客K-ing11 小时前
网络安全防范
linux·服务器·web安全
王三三12 小时前
群晖利用acme.sh自动申请证书并且自动重载证书的问题解决
linux·自动化·证书·群晖·acme·acme.sh·lets encrypt
路飞雪吖~12 小时前
【Linux】进程控制
linux·运维·服务器
wy02_12 小时前
Linux基本命令
linux·运维