Advertisement
pleasedontcode

WiFi Sniffer

Aug 5th, 2024
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.73 KB | Source Code | 0 0
  1. #include "WiFi.h"
  2.  
  3. void setup() {
  4.   Serial.begin(115200);
  5.   WiFi.mode(WIFI_MODE_STA);
  6.   esp_wifi_set_promiscuous(true);
  7.   esp_wifi_set_promiscuous_filter(&filter);
  8.   esp_wifi_set_promiscuous_rx_cb(&sniffer_callback);
  9.   esp_wifi_start();
  10. }
  11.  
  12. void loop() {
  13.   // Nothing to do here - everything happens in the callback
  14. }
  15.  
  16. void sniffer_callback(void* buf, wifi_promiscuous_pkt_type_t type) {
  17.   const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buf;
  18.   Serial.print("Packet: ");
  19.   for (int i = 0; i < ppkt->rx_ctrl.sig_len; i++) {
  20.     Serial.print(ppkt->payload[i], HEX);
  21.     Serial.print(" ");
  22.   }
  23.   Serial.println();
  24. }
  25.  
  26. wifi_promiscuous_filter_t filter = {
  27.     .filter_mask = WIFI_PROMIS_FILTER_MASK_ALL,
  28. };
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement