Skip to content

Instantly share code, notes, and snippets.

@dpavlin
Forked from kost/esp8266-wifi-beacon-generator.ino
Last active April 17, 2021 14:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpavlin/b8a966340e49c59d4642e983cde48ffb to your computer and use it in GitHub Desktop.
Save dpavlin/b8a966340e49c59d4642e983cde48ffb to your computer and use it in GitHub Desktop.
ESP8266 WiFi Beacon Generator - Generate SSID beacon frames on ESP8226
#include <ESP8266WiFi.h>
extern "C" {
#include "user_interface.h"
}
byte channel;
#define MAX_SSID 10 /* how much SSIDs we have */
char *ssids[MAX_SSID] = {
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten"
};
byte rnd;
byte i;
byte count;
byte wifipkt[128] = { 0x80, 0x00, 0x00, 0x00,
/*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
/*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
/*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
/*22*/ 0xc0, 0x6c,
/*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00,
/*32*/ 0x64, 0x00,
/*34*/ 0x01, 0x04,
/* SSID */
/*36*/ 0x00};
byte pktsuffix[] = {
0x01, 0x08, 0x82, 0x84,
0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, 0x03, 0x01,
0x04 };
void setup() {
delay(500);
wifi_set_opmode(STATION_MODE);
wifi_promiscuous_enable(1);
}
void loop() {
wifipkt[10] = wifipkt[16] = random(256);
wifipkt[11] = wifipkt[17] = random(256);
wifipkt[12] = wifipkt[18] = random(256);
wifipkt[13] = wifipkt[19] = random(256);
wifipkt[14] = wifipkt[20] = random(256);
wifipkt[15] = wifipkt[21] = random(256);
count=37;
rnd=random(MAX_SSID);
wifipkt[count++]=strlen(ssids[rnd]);
for (i=0; i<strlen(ssids[rnd]); i++) {
wifipkt[count++]=ssids[rnd][i];
}
for (i=0; i<sizeof(pktsuffix); i++) {
wifipkt[count++]=pktsuffix[i];
}
channel = random(1,12);
wifi_set_channel(channel);
wifipkt[count-1] = channel;
wifi_send_pkt_freedom(wifipkt, count, 0);
wifi_send_pkt_freedom(wifipkt, count, 0);
wifi_send_pkt_freedom(wifipkt, count, 0);
delay(1);
}
builder:
/opt/arduino-1.6.8/arduino-builder -dump-prefs -logger=machine -hardware "/opt/arduino-1.6.8/hardware" -hardware "/home/dpavlin/.arduino15/packages" -hardware "/home/dpavlin/Arduino/hardware" -tools "/opt/arduino-1.6.8/tools-builder" -tools "/opt/arduino-1.6.8/hardware/tools/avr" -tools "/home/dpavlin/.arduino15/packages" -built-in-libraries "/opt/arduino-1.6.8/libraries" -libraries "/home/dpavlin/Arduino/libraries" -fqbn=esp8266:esp8266:generic:CpuFrequency=80,FlashFreq=40,FlashMode=dio,UploadSpeed=115200,FlashSize=512K64,ResetMethod=nodemcu,Debug=Disabled,DebugLevel=None____ -ide-version=10608 -build-path "/tmp/build74183724a5572046762b09cc6849235c.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "/home/dpavlin/Arduino/esp8266_spam/esp8266_spam.ino"
/opt/arduino-1.6.8/arduino-builder -compile -logger=machine -hardware "/opt/arduino-1.6.8/hardware" -hardware "/home/dpavlin/.arduino15/packages" -hardware "/home/dpavlin/Arduino/hardware" -tools "/opt/arduino-1.6.8/tools-builder" -tools "/opt/arduino-1.6.8/hardware/tools/avr" -tools "/home/dpavlin/.arduino15/packages" -built-in-libraries "/opt/arduino-1.6.8/libraries" -libraries "/home/dpavlin/Arduino/libraries" -fqbn=esp8266:esp8266:generic:CpuFrequency=80,FlashFreq=40,FlashMode=dio,UploadSpeed=115200,FlashSize=512K64,ResetMethod=nodemcu,Debug=Disabled,DebugLevel=None____ -ide-version=10608 -build-path "/tmp/build74183724a5572046762b09cc6849235c.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "/home/dpavlin/Arduino/esp8266_spam/esp8266_spam.ino"
@dpavlin
Copy link
Author

dpavlin commented Jul 18, 2016

@kost I have no idea how to submit pull request on gist :-)

@Ash-newbee
Copy link

Pls tell ...why to write wifi_send_pkt_freedom 3 times

@dpavlin
Copy link
Author

dpavlin commented Apr 17, 2021

Pls tell ...why to write wifi_send_pkt_freedom 3 times

You would have to ask @kost who is original author, but I guess if idea is to generate as much beacons as possible on all channels, sending multiple beacons also makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment