如何确定 wifi AP/网络使用的 wifi 通道号?
我发现几个 Android wifi 应用程序(WiFi 管理器、WiFi 分析器)除了 BSSID/SSID 等之外还显示 WiFi 网络的通道号。但我找不到有关它们如何执行此操作的任何信息。我唯一知道的是我可以获得一些 wifi 频率。也许他们确定了与该频率相对应的频道?有没有办法在android中检测wifi网络的通道?当然,这个信息没什么大不了的,没有它我也可以生活:)但我仍然很好奇......
Ive discovered that several android wifi-apps (WiFi Manager, WiFi Analyzer) shows a channel number of WiFi network additionally to BSSID/SSID etc. But I can't find any info on how they do it. The only thing I know is I can get some wifi frequency. Maybe they determine a channel corresponding to that frequency? Is there a way to detect channel of wifi network in android at all? Of course this info is not a big deal and I can live without it :) but still i'm curious...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
根据无线电电子学。 com,频道数确实与频率相关。
对于 Android,ScanResult 包含频道的频率。
According to Radio-Electronics.com, channel number is truly related with frequency.
For Android, ScanResult contains the frequency of the channel.
您可以使用几个公式来表达转换,每个公式一个。该函数返回给定频率的频道,如果该频率不是有效的 WiFi 频率(2.4GHz 和 5GHz),则返回 -1。
这是执行相同操作的紧凑方法。
You can express the conversion using a couple of formulas, one for each band. The function returns the channel of the given frequency or -1 in case that the frequency is not a valid wifi frequency (2.4GHz and 5GHz).
It is a compact way to do the same.
根据标准[802.11-2012],有一种更简单的方法可以从频率计算出通道数。具体来说,
channel_center_Frequency = Channel_starting_Frequency + 5 * Channel_number
对于 5G 频段,
频道号
= 0, 1, ..., 200;channel_starting_Frequency
= 5000 MHz。对于2.4G频段,
频道号
= 1, 2, ..., 13;channel_starting_Frequency
= 2047 MHz。所有频道频率的列表可以在 WiFi 频道 中找到
将其转换为代码 - 请参阅
iw
来源:According to standard [802.11-2012], there is a simpler way to work out channel number from frequency. Specifically,
channel_center_frequency = channel_starting_frequency + 5 * channel_number
For 5G band,
channel_number
= 0, 1, ..., 200;channel_starting_frequency
= 5000 MHz.For 2.4G band,
channel_number
= 1, 2, ..., 13;channel_starting_frequency
= 2047 MHz.The list of all channel frequencies can be found at WiFi channels
Translating this into code - refer to
iw
source:添加到@artm的回答,这里是在Linux源代码中找到的更新的算法:
来源:https://github.com/torvalds/linux/blob/master /net/wireless/util.c#L141,函数名称:
ieee80211_freq_khz_to_channel
Adding to the answer by @artm, here is a more updated algorithm found in the Linux source code:
Source: https://github.com/torvalds/linux/blob/master/net/wireless/util.c#L141, function name:
ieee80211_freq_khz_to_channel