| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /// import all of the common libs
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <WiFiAP.h>
- #include <WebServer.h>
- #include <uri/UriBraces.h>
- #include <ESPmDNS.h>
- #include "esp_wifi.h" // common esp wifi methods
- #include "web.h" // our webpage contfigs
- #include "config.h" // out newtowrk configs
- WebServer server(port);
- void handleRoot() {
- String message = "<h1>Actions</h1>";
- String response = formatContent("Actions", message);
- server.send(200, "text/html", response);
- }
- void handleClients() {
- String message = "Client list\n\n";
- wifi_sta_list_t wifi_sta_list;
- tcpip_adapter_sta_list_t adapter_sta_list;
- esp_wifi_ap_get_sta_list(&wifi_sta_list);
- tcpip_adapter_get_sta_list(&wifi_sta_list, &adapter_sta_list);
- if (adapter_sta_list.num > 0) {
- for (uint8_t i = 0; i < adapter_sta_list.num; i++) {
- tcpip_adapter_sta_info_t station = adapter_sta_list.sta[i];
- ip_addr_t client_ip_addr;
- memcpy((char *)&client_ip_addr.u_addr.ip4, (char *)&station.ip, sizeof(ip4_addr));
- client_ip_addr.type = IPADDR_TYPE_V4;
- message += ((String) "[+] Device " + i + " ");
- message += ("%02X:%02X:%02X:%02X:%02X:%02X", station.mac[0], station.mac[1], station.mac[2], station.mac[3], station.mac[4], station.mac[5]);
- message += (" ");
- message += (ip4addr_ntoa(&(client_ip_addr.u_addr.ip4)));
- message += ("\n");
- }
- }
- String response = formatContent("Clients", "<pre>" + message + "</pre>");
- server.send(200, "text/html", response);
- }
- void handleStatus() {
- String message = "<h1>Online</h1>";
- String response = formatContent("Status", message);
- server.send(200, "text/html", response);
- }
- String formatContent(String title, String content) {
- String response = (String) page_header + (String) page_nav + (String) page_content + (String) page_footer;
- response.replace("__TITLE__", title);
- response.replace("__CONTENT__", content);
- server.send(200, "text/html", response);
- }
- void setup() {
- Serial.begin(baud);
- Serial.println("\n[+] Creating AP");
- WiFi.mode(WIFI_AP);
- WiFi.softAP(ssid, password, channel, hide_SSID, max_connection);
-
- Serial.println((String) " --> ssid: " + ssid);
- Serial.println((String) " --> password: " + password);
- Serial.println((String) " --> channel: " + channel);
- Serial.println((String) " --> hide ssid: " + hide_SSID);
- Serial.println((String) " --> max connections: " + max_connection);
- Serial.println(" --> ip address: 10.10.10.1");
- Serial.println(" --> gateway: 10.10.10.1");
- Serial.println(" --> subnet: 255.255.255.0");
-
- delay(100);
- WiFi.softAPConfig(ip, ip, subnet);
- delay(100);
- IPAddress myIP = WiFi.softAPIP();
- delay(100);
- MDNS.begin(host);
-
- server.on("/", handleRoot);
- server.on("/clients", handleClients);
- server.on("/status", handleStatus);
- server.onNotFound(handleRoot);
- server.begin();
-
- delay(100);
- MDNS.addService("http", "tcp", port);
- Serial.print("[+] HTTP server started: http://");
- Serial.print(host);
- Serial.print(", http://");
- Serial.println(myIP);
- }
- void loop() {
- server.handleClient();
- delay(2);
- }
|