获取AP的状态信息(hostapd_cli)

通过hostapd创建了AP热点,但是Linux如何知道都有哪些设备连接到了AP呢?

hostapd是个后台服务程序,我们想知道它的状态可以通过hostapd_cli客户端对hostapd进行访问,进而获取到AP的状态和控制AP相关的功能。

下面是hostapd功能框架

hostapd_cli与hostapd是通过本地socket进行通信的,这个socket是hostapd启动以后根据hostapd.conf文件中的配置进行创建的,默认情况下的配置为:

# Interface for separate control program. If this is specified, hostapd
# will create this directory and a UNIX domain socket for listening to requests
# from external programs (CLI/GUI, etc.) for status information and
# configuration. The socket file will be named based on the interface name, so
# multiple hostapd processes/interfaces can be run at the same time if more
# than one interface is used.
# /var/run/hostapd is the recommended directory for sockets and by default,
# hostapd_cli will use it when trying to connect with hostapd.
ctrl_interface=/var/run/hostapd

默认情况下,hostapd_cli会连接到/var/run/hostapd下面的socket。

如果在hostapd.conf中没有指定ctrl_interface,那么hostapd是不会产生通信的socket共客户端访问,此时输入hostapd_cli会产生如下错误。

hostapd_cli v2.9
Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi> and contributorsThis software may be distributed under the terms of the BSD license.
See README for more details.Could not connect to hostapd - re-trying

当然,ctrl_interface也可以自动定义,那么输入hostapd_cli时也需要指定这个对应的路径,一般不建议这么做。

我模拟AP的网卡是wlan0,当我启动hostapd后,会在/var/run/hostapd目录下创建一个socket,供客户端访问

# pwd
/var/run/hostapd
# ls -l
total 0
srwxrwx---    1 root     root             0 Jun 29 01:37 wlan0
# 

hostapd_cli客户端使用

启动hostapd_cli客户端

在命令行中直接输入hostapd_cli命令即可。如果ctrl_interface不是默认参数,则需要输入hostapd_cli -s<dir_path>指定参数。输入命令后,出现交互命令行,则代表hostapd_cli与hostapd通信成功,可以进行其他功能的访问。

#
# hostapd_cli
hostapd_cli v2.9
Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi> and contributorsThis software may be distributed under the terms of the BSD license.
See README for more details.Selected interface 'wlan0'Interactive mode>
>
>
>
> 

输入help查看帮助信息

>
>
>
> help
commands:ping = pings hostapdmib = get MIB variables (dot1x, dot11, radius)relog = reload/truncate debug log output filestatus = show interface status infosta <addr> = get MIB variables for one stationall_sta = get MIB variables for all stationslist_sta = list all stationsnew_sta <addr> = add a new stationdeauthenticate <addr> = deauthenticate a stationdisassociate <addr> = disassociate a stationsa_query <addr> = send SA Query to a stationwps_pin <uuid> <pin> [timeout] [addr] = add WPS Enrollee PINwps_check_pin <PIN> = verify PIN checksumwps_pbc = indicate button pushed to initiate PBCwps_cancel = cancel the pending WPS operationwps_nfc_tag_read <hexdump> = report read NFC tag with WPS datawps_nfc_config_token <WPS/NDEF> = build NFC configuration tokenwps_nfc_token <WPS/NDEF/enable/disable> = manager NFC password tokenwps_ap_pin <cmd> [params..] = enable/disable AP PINwps_config <SSID> <auth> <encr> <key> = configure APwps_get_status = show current WPS statusdisassoc_imminent = send Disassociation Imminent notificationess_disassoc = send ESS Dissassociation Imminent notificationbss_tm_req = send BSS Transition Management Requestget_config = show current configurationhelp = show this usage helpinterface [ifname] = show interfaces/select interfaceraw <params..> = send unprocessed commandlevel <debug level> = change debug levellicense = show full hostapd_cli licensequit = exit hostapd_cliset <name> <value> = set runtime variablesget <name> = get runtime infoset_qos_map_set <arg,arg,...> = set QoS Map set elementsend_qos_map_conf <addr> = send QoS Map Configure framechan_switch <cs_count> <freq> [sec_channel_offset=] [center_freq1=][center_freq2=] [bandwidth=] [blocktx] [ht|vht]= initiate channel switch announcemenths20_wnm_notif <addr> <url>= send WNM-Notification Subscription Remediation Requesths20_deauth_req <addr> <code (0/1)> <Re-auth-Delay(sec)> [url]= send WNM-Notification imminent deauthentication indicationvendor <vendor id> <sub command id> [<hex formatted data>]= send vendor driver commandenable = enable hostapd on current interfacereload = reload configuration for current interfacedisable = disable hostapd on current interfaceupdate_beacon = update Beacon frame contentserp_flush = drop all ERP keyslog_level [level] = show/change log verbosity levelpmksa  = show PMKSA cache entriespmksa_flush  = flush PMKSA cacheset_neighbor <addr> <ssid=> <nr=> [lci=] [civic=] [stat]= add AP to neighbor databaseremove_neighbor <addr> <ssid=> = remove AP from neighbor databasereq_lci <addr> = send LCI request to a stationreq_range  = send FTM range requestdriver_flags  = show supported driver flagsaccept_acl =Add/Delete/Show/Clear accept MAC ACLdeny_acl =Add/Delete/Show/Clear deny MAC ACLpoll_sta <addr> = poll a STA to check connectivity with a QoS null framereq_beacon <addr> [req_mode=] <measurement request hexdump>  = send a Beacon report request to a stationreload_wpa_psk = reload wpa_psk_file only
> 

查看所有已连接设备的信息

这样我们可以看到已连接设备的mac地址,连接时间等信息

> all_sta
ba:ba:3f:a9:cd:d4
flags=[AUTH][ASSOC][AUTHORIZED]
aid=0
capability=0x0
listen_interval=0
supported_rates=0c 18 30
timeout_next=NULLFUNC POLL
dot11RSNAStatsSTAAddress=ba:ba:3f:a9:cd:d4
dot11RSNAStatsVersion=1
dot11RSNAStatsSelectedPairwiseCipher=00-0f-ac-4
dot11RSNAStatsTKIPLocalMICFailures=0
dot11RSNAStatsTKIPRemoteMICFailures=0
wpa=2
AKMSuiteSelector=00-0f-ac-2
hostapdWPAPTKState=11
hostapdWPAPTKGroupState=0
rx_packets=0
tx_packets=0
rx_bytes=0
tx_bytes=0
inactive_msec=4000
signal=0
rx_rate_info=0
tx_rate_info=0
connected_time=1415
> 

取消一个设备的接入认证

这样sta设备就会断开连接,但是如果sta选择的是自动连接,那么ap强制断开sta后,sta还会自动连接到AP。

> deauthenticate ba:ba:3f:a9:cd:d4
[ 5040.294654] [dhd-wlan0] wl_cfg80211_del_station : Disconnect STA ba:ba:3f:a9:cd:d4 scb_val.val 3
<3>AP-STA-DISCONNECTED ba:ba:3f:a9:cd:d4
[ 5040.306529] [dhd-wlan0] wl_cfg80211_del_station : Disconnect STA ba:ba:3f:a9:cd:d4 scb_val.val 3
OK
> [ 5040.749799] [dhd-wlan0] wl_ext_iapsta_event : [0 times] [A] disconnected device ba:ba:3f:a9:cd:d4, WLC_E_DEAUTH(5), reason=3
[ 5040.761421] [dhd-wlan0] wl_notify_connect_status_ap : [0 times] event WLC_E_DEAUTH(5) status 0 reason 3
[ 5040.771145] [dhd-wlan0] wl_notify_connect_status_ap : [0 times] deauthenticated device ba:ba:3f:a9:cd:d4
[ 5040.782470] [dhd-wlan0] wl_cfg80211_del_station : Disconnect STA ba:ba:3f:a9:cd:d4 scb_val.val 3
[ 5041.042141] [dhd-wlan0] wl_ext_iapsta_event : [A] connected device ba:ba:3f:a9:cd:d4
[ 5041.050166] [dhd-wlan0] wl_notify_connect_status_ap : connected device ba:ba:3f:a9:cd:d4
[ 5041.058726] [dhd] CFG80211-ERROR) wl_cfg80211_change_station : WLC_SCB_AUTHORIZE sta_flags_mask not set
<3>AP-STA-CONNECTED ba:ba:3f:a9:cd:d4>
> 

还可以取消设备的关联等,这里不再一一列举。

这是命令行对hostapd通过交互的方式对hostapd进行访问,那如果要是c语言应用程序,如何访问hostapd状态呢?后面文章继续介绍。

参考链接:

http://w1.fi/wpa_supplicant/devel/

https://forum.huawei.com/enterprise/zh/thread-232281.html

嵌入式Linux热点分享网络(四)相关推荐

  1. 苹果Mac笔记本电脑如何开启热点分享网络?

    苹果除了在iPhone 上有设计热点分享的功能之外,其实Mac 笔记本电脑很早就已经可以开启类似热点分享网络的功能了,在没有Wi-Fi 只提供有线网路的地方相当好用,来看看要在苹果Mac上如何开启热点 ...

  2. 嵌入式Linux文件提取,嵌入式 Linux系统编程(四)——文件属性

    嵌入式 Linux系统编程(四)--文件属性 一.文件属性概述 Linux 文件的属性主要包括:文件的节点.种类.权限模式.链接数量.所归属的用户和用户组.最近访问或修改的时间等内容.文件属性示例如下 ...

  3. linux 嵌入式汇编 adc,嵌入式Linux ARM汇编(四)——ARM汇编程序设计

    嵌入式Linux ARM汇编(四)--ARM汇编程序设计 汇编程序有顺序.循环.分支.子程序四种结构形式. 一.顺序结构 程序实例: AREA Buf,DATA,READWRITE;定义数据段Buf ...

  4. 嵌入式项目_嵌入式Linux项目分享_linux系统编程

    分享一个适合入门嵌入式linux系统编程的项目,其他项目见:牛客嵌入式项目 同时附上本人编写的两个牛客高级专栏: <100道安卓常见面试题全解析> <嵌入式 面经C++软件开发 面经 ...

  5. linux驱动的中断函数,嵌入式Linux驱动开发(四)——字符设备驱动之中断方式以及中断方式获取按键值...

    之前我们完成了关于通过查询的方式获取按键键值的驱动程序,可以参考:嵌入式Linux开发--裸板程序之中断控制器. 虽然读取键值没有什么问题,但是测试程序占用CPU过高,一直在不断的查询,资源消耗过大, ...

  6. Linux热点无网络,Linux网络配置:手提在连接WIFI热点情况下,Ubuntu16.04中怎样配置网络?...

    Linux网络配置:手提在连接WIFI热点情况下,Ubuntu16.04中怎样配置网络?,范佩西致敬温格:你是我的足球父亲,是你塑造了我,磷菩屹倨竿,布加迪推出Chiron Sport特别版,百公里加 ...

  7. 嵌入式 linux 系统开发网络的设置

    目录 一.前言 二.linux网络静态地址设置 前言 为什么要对linux系统下的ubuntu进行网络设置呢? 因为我们在嵌入式开发中,我们要保证windows系统.linux系统.开发板的ip要处于 ...

  8. Linux内核分析 - 网络[四]:路由表

    路由表 在内核中存在路由表fib_table_hash和路由缓存表rt_hash_table.路由缓存表主要是为了加速路由的查找,每次路由查询都会先查找路由缓存,再查找路由表.这和cache是一个道理 ...

  9. 实现嵌入式linux自动同步网络时间---NTP

    因为ARM板断电重启问题,为保证能获取到准确的实时时间,所以需要实现自动从网络上获取时间,这就需要用到NTP.NTP是网络时间协议(Network Time Protocol)的简称,它是用来同步网络 ...

最新文章

  1. 1807. [NOIP2014]寻找道路P2296 寻找道路
  2. DHCP在企业网中的应用
  3. 数据结构的定义和简介
  4. es根据字段长度过滤_Es 根据数组长度查询
  5. 2018年10月Top 10 Python开源项目
  6. Linux 网络编程详解四(流协议与粘包)
  7. 【Unity】关于屏幕自适应的思路
  8. html游戏图标库,又一款开源图标库 CSS.GG,值得一用
  9. C语言实例 区分旅客国籍
  10. SuseLinux详解(1)——设置开机启动为命令行模式
  11. (五):ionic 命令详解
  12. Oracle常用操作【自己的练习】
  13. 谈谈tomcat引起的中文乱码问题
  14. WeChat for Linux
  15. MATLAB视频与图片之间的相互转换
  16. 科普 | 金融衍生品系列——互换
  17. JAVA|大小写英文字母表
  18. linux 安装 gdrive
  19. uniapp插件市场-涂图视频编辑-美妆-剪辑-微整形原生sdk插件发布-优雅草科技
  20. 详解 Java 日期与时间

热门文章

  1. 已解决:error: cannot connect to daemon
  2. netty tcp空闲设置
  3. 如何修改安卓应用图标和程序名称
  4. HTML5 CSS3 专题 :诱人的实例 3D旋转木马效果相冊
  5. Linux驱动:网卡驱动分析之三--MAC驱动及PHY驱动框架了解
  6. ansible一键部署脚本
  7. 从认知智能的角度认识ChatGPT的不足
  8. 散转程序c语言,单片机 散转表程序的使用
  9. 兑吧解决Windows 组件存储已损坏,0x80073712错误
  10. C++版-剑指offer 面试题6:重建二叉树(Leetcode105. Construct Binary Tree from Preorder and Inorder Traversal) 解题报告