Friday, December 6, 2024

ESP8266 WEMOS D1 || PACKET MONITOR


#include <ESP8266WiFi.h>
#include <Wire.h>
#include <EEPROM.h>
 
#include "SSD1306.h"
 
extern "C" {
#include "user_interface.h"
}
 
SSD1306 display(0x3c, 5, 4);   // GPIO 5 = D1, GPIO 4 = D2 پین های مربوط
 
#define btn D3         // Nodemcu
 
#define maxCh 13       //   US = 11, EU = 13, Japan = 14 
#define ledPin 2       // LED
#define packetRate 5   //
 
#define flipDisplay true
 
#define minRow       0          
#define maxRow     127              
#define minLine      0              
#define maxLine     63              
 
#define Row1         0
#define Row2        30
#define Row3        35
#define Row4        80
#define Row5        85
#define Row6       125
 
#define LineText     0
#define Line        12
#define LineVal     47
 
 
unsigned long prevTime   = 0;
unsigned long curTime    = 0;
unsigned long pkts       = 0;
unsigned long no_deauths = 0;
unsigned long deauths    = 0;
int curChannel           = 1;
unsigned long maxVal     = 0;
double multiplicator     = 0.0;
bool canBtnPress         = true;
 
unsigned int val[128];
 
void sniffer(uint8_t *buf, uint16_t len) {
  pkts++;
  if (buf[12] == 0xA0 || buf[12] == 0xC0) {
    deauths++;
  }
}
 
void getMultiplicator() {
  maxVal = 1;
  for (int i = 0; i < maxRow; i++) {
    if (val[i] > maxVal) maxVal = val[i];
  }
  if (maxVal > LineVal) multiplicator = (double)LineVal / (double)maxVal;
  else multiplicator = 1;
}
 
 
void setup() {
 
  display.init();
  if (flipDisplay) display.flipScreenVertically();
 
  Serial.begin(115200);
 
  EEPROM.begin(4096);
  curChannel = EEPROM.read(2000);
  if (curChannel < 1 || curChannel > maxCh) {
    curChannel = 1;
    EEPROM.write(2000, curChannel);
    EEPROM.commit();
  }
 
  pinMode(ledPin, OUTPUT);
 
 
  wifi_set_opmode(STATION_MODE);
  wifi_promiscuous_enable(0);
  WiFi.disconnect();
  wifi_set_promiscuous_rx_cb(sniffer);
  wifi_set_channel(curChannel);
  wifi_promiscuous_enable(1);
 
  Serial.println("starting!");
}
 
void loop() {
  curTime = millis();
 
  if (digitalRead(btn) == LOW) {
    if (canBtnPress) canBtnPress = false;
  } else if (!canBtnPress) {
    canBtnPress = true;
 
    curChannel++;
    if (curChannel > maxCh) curChannel = 1;
    wifi_set_channel(curChannel);
    for (int i = 0; i < maxRow; i++) val[i] = 0;
    pkts = 0;
    multiplicator = 1;
 
    EEPROM.write(2000, curChannel);
    EEPROM.commit();
 
    if (pkts == 0) pkts = deauths;
    no_deauths = pkts - deauths;
 
    display.clear();
    display.drawLine(minRow, Line, maxRow, Line);
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.drawString(Row1, LineText, "Ch:");
    display.drawString(Row3, LineText, "Pkts:");
    display.drawString(Row5, LineText, "DA:");
    display.setTextAlignment(TEXT_ALIGN_RIGHT);
    display.drawString(Row2, LineText, (String)curChannel);
    display.drawString(Row4, LineText, (String)no_deauths);
    display.drawString(Row6, LineText, (String)deauths);
    for (int i = 0; i < maxRow; i++) display.drawLine(i, maxLine, i, maxLine - val[i]*multiplicator);
    display.display();
  }
 
  if (curTime - prevTime >= 1000) {
    prevTime = curTime;
 
    for (int i = 0; i < maxRow; i++) {
      val[i] = val[i + 1];
    }
    val[127] = pkts;
 
    getMultiplicator();
 
    if (deauths > packetRate) digitalWrite(ledPin, LOW);
    else digitalWrite(ledPin, HIGH);
 
    if (pkts == 0) pkts = deauths;
    no_deauths = pkts - deauths;
 
    display.clear();
    display.drawLine(minRow, Line, maxRow, Line);
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.drawString(Row1, LineText, "Ch:");
    display.drawString(Row3, LineText, "Pkts:");
    display.drawString(Row5, LineText, "DA:");
    display.setTextAlignment(TEXT_ALIGN_RIGHT);
    display.drawString(Row2, LineText, (String)curChannel);
    display.drawString(Row4, LineText, (String)no_deauths);
    display.drawString(Row6, LineText, (String)deauths);
    for (int i = 0; i < maxRow; i++) display.drawLine(i, maxLine, i, maxLine - val[i]*multiplicator);
    display.display();
 
    deauths    = 0;
    pkts       = 0;
  }
}

 
 
 
 

No comments:

Post a Comment

Current Project

Bypassing Paywalls with Curl by Deon V.

  Sometimes you just want to read an article, but there is a popup that stops you, asking to subscribe in someway. Although there ar...