Como construir um sniffer WiFi MicroPython

How to build a MicroPython WiFi sniffer

MAC layer protocols such as WiFi/WLAN, Zigbee, Bluetooth and Ethernet are of prime importance in IoT applications. WiFi/WLAN is one of the most used wireless solutions in home automation, smart agriculture, office automation and industrial IoT. It is highly critical that controllers in IoT devices identify and connect to available WiFi networks and communicate data packets effectively over a secure channel. WiFi, despite having a limited range, offers incredible bandwidth, so even applications like live streaming can easily be hosted on a WiFi network. WiFi-based IoT applications need to accomplish one thing, whether they require a large bandwidth or not: WiFi detection.

In network engineering, a WiFi Sniffer is a network analyzer designed to capture packet data on the wireless network. In embedded applications, a dedicated WiFi Sniffer is rarely needed to monitor a WiFi network. However, some functionality of a WiFi Sniffer often needs to be built into IoT devices. One of these features is the identification of available WiFi networks and the ability to connect to an available WiFi channel. In this article, we will look at exactly what a WiFi Sniffer is. Why is this necessary on a wireless network? How is WiFi detection used in embedded applications? How can WiFi detection be implemented on MicroPython ports?

What is a WiFi sniffer?
A WiFi Sniffer is a passive listening device that captures WiFi network frames from a given WiFi channel over the air. A Sniffer only listens for WiFi network packets of a specific bandwidth within its listening capability range. Currently, WiFi networks use only two bandwidths – 2.4 GHz and 5 GHz. The latest version of WiFi i.e. WiFi 6E uses an additional bandwidth of 6 GHz.

A dedicated WiFi Sniffer specifically deployed to monitor the wireless network shares the same channel that acts as a communication medium between an access point and station devices and continues capturing wireless frames to monitor and record information about wireless traffic on a file. A WiFi Sniffer captures all frames communicated between a WiFi access point and a device that acts as a WiFi station on the same channel, but does not process frames or respond to the network. Dedicated WiFi sniffers are only required in IoT applications where it is important to ensure wireless connectivity of the network or high-bandwidth data is frequently communicated within the network, such as in the case of video streaming or a highly active large sensor network. scale.

WiFi sniffer applications
WiFi detection is used to scan devices on a wireless network. It also configures connection procedures between station devices and WiFi access points. During network deployment, WiFi detection is often used to verify frame accuracy and ensure that frames are transmitted over the air. The protocol is also used to confirm the compatibility of devices with the WiFi network. WiFi detection is often used for network validation and pre-certification of WiFi-enabled devices. Last but not least, WiFi detection also is used to troubleshoot WiFi networks and station devices within the network.

WiFi sniffer types
There are two types of WiFi sniffers: software-based and dedicated. Software-based WiFi Sniffers are software applications or features built into an application designed for WiFi detection. The software driver needs to be installed on a WiFi adapter to perform detection. WiFi detection software can often be incompatible with the intended hardware platform. A dedicated WiFi Sniffer is a WiFi adapter with WiFi detection capability built into its software or firmware.

Using WiFi Sniffer on embedded microcontrollers
Microcontrollers are often not very capable in terms of acting as a full WiFi sniffer. However, WiFi-enabled microcontrollers are often programmed to perform some of the WiFi sensing functions. This includes identifying WiFi access points and connecting other station devices to the same network once connected. The functionality to communicate with a WiFi network for data communication over the Internet is also a WiFi detection function. The functionality to reset and reconnect to a WiFi network is another WiFi detection function.

WiFi sniffing on MicroPython ports
Most MicroPython ports have built-in or on-chip WiFi. These microcontrollers are already WiFi adapters that can connect to a WiFi network both as a station device and as an access point. Fortunately, the MicroPython network module is designed to connect and communicate with a WiFi network. The network module's WLAN class can check the MAC address of all devices connected to the WiFi network. The same class configures the port as a WiFi access point or a station device.

MicroPython Script for WiFi Detection
You can upload the following MicroPython script to any WiFi-enabled MicroPython port. The script scans available WiFi networks and lists the MAC addresses of devices in the range.

The code
The code starts by importing the WLAN class from the WiFi module. Next, the ubinascii module is imported to allow the conversion of binary data to ASCII format. A scan_wifi function is defined in which the MAC address, WiFi packet and packet control bit are retrieved. The control bit is used to identify the type of MAC address. If the MAC address is valid, it will be printed on the console. A WLAN class object is instantiated in the code, and the scan_wifi function is called as a callback function as soon as a management packet is received in promiscuous mode. WiFi promiscuous mode on the port is activated by calling the wlan.promiscuous method. Promiscuous mode ensures that each transmitted data packet is received and read by the WiFi adapter.

Conteúdo Relacionado

A network of sensors is embedded in every vehicle,...
The motor controller is one of the most important...
ESP32-CAM is a compact camera module that combines the...
A evolução dos padrões USB foi fundamental para moldar...
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A Sealevel Systems anuncia o lançamento da Interface Serial...
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
Determinar uma localização precisa é necessário em várias indústrias...
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
O mercado embarcado tem uma necessidade de soluções de...
You have probably come across the term ' drag...
You probably have a support insulator if you've noticed...
You've probably seen stand an insulator sit on power...
You've probably seen shackle insulators enthroned on electricity poles,...
You have probably experienced situations where controlling a circuit...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.