Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **WiFi Connection**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-04-22 18:11:00
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Create a firmware that function as a MAC sniffer */
- /* and post data to an api */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <HTTPClient.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void startWiFi();
- void sniffMACAddresses();
- void postDataToAPI(const String &macAddress);
- /****** GLOBAL VARIABLES *****/
- const char* ssid = "your_SSID"; // Replace with your WiFi SSID
- const char* password = "your_PASSWORD"; // Replace with your WiFi password
- const char* apiEndpoint = "http://your_api_endpoint"; // Replace with your API endpoint
- void setup(void)
- {
- Serial.begin(115200);
- startWiFi();
- }
- void loop(void)
- {
- sniffMACAddresses();
- delay(10000); // Delay between scans
- }
- void startWiFi() {
- // Connect to WiFi
- Serial.print("Connecting to WiFi...");
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.print(".");
- }
- Serial.println("Connected to WiFi");
- }
- void sniffMACAddresses() {
- // Scan for available networks
- int n = WiFi.scanNetworks();
- Serial.println("Scan complete, found networks:");
- for (int i = 0; i < n; ++i) {
- String macAddress = WiFi.BSSIDstr(i); // Get MAC address of the network
- Serial.print("Network: ");
- Serial.print(WiFi.SSID(i));
- Serial.print(" | MAC: ");
- Serial.println(macAddress);
- // Post MAC address to API
- postDataToAPI(macAddress);
- }
- }
- void postDataToAPI(const String &macAddress) {
- if (WiFi.status() == WL_CONNECTED) {
- HTTPClient http;
- http.begin(apiEndpoint); // Specify the URL
- http.addHeader("Content-Type", "application/json"); // Specify content-type header
- // Create JSON payload
- String payload = "{\"macAddress\":\"" + macAddress + "\"}";
- int httpResponseCode = http.POST(payload); // Send the request
- if (httpResponseCode > 0) {
- String response = http.getString(); // Get response
- Serial.println(httpResponseCode); // Print return code
- Serial.println(response); // Print response
- } else {
- Serial.print("Error on sending POST: ");
- Serial.println(httpResponseCode);
- }
- http.end(); // Free resources
- } else {
- Serial.println("WiFi not connected");
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement