A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
Network discovery functions
Andrei Vladescubb749337e441
diff --git a/src/Abstracts/ANetworkController.cpp b/src/Abstracts/ANetworkController.cppindex 2155bade..e92cd767 100644--- a/src/Abstracts/ANetworkController.cpp+++ b/src/Abstracts/ANetworkController.cpp@@ -64,7 +64,7 @@ void ANetworkController::handleDiscovery(const TerminalCommand &cmd){bool wifiConnected = wifiService.isConnected();bool ethConnected = ethernetService.isConnected();- phy_interface_t phy_interface = phy_interface_t::None;+ phy_interface_t phy_interface = phy_interface_t::phy_none;if (!wifiConnected && !ethConnected) {terminalView.println("Discovery: You must be connected to Wi-Fi or Ethernet. Use 'connect' first.");@@ -76,27 +76,27 @@ void ANetworkController::handleDiscovery(const TerminalCommand &cmd)if (cmd.getSubcommand().empty() || args.size() < 1) {if (wifiConnected){terminalView.println("Discovery: Using WiFi as default interface.");- phy_interface = phy_interface_t::WiFi;+ phy_interface = phy_interface_t::phy_wifi;}else{terminalView.println("Discovery: Using Ethernet as default interface.");- phy_interface = phy_interface_t::Eth;+ phy_interface = phy_interface_t::phy_eth;}}else {if (cmd.getSubcommand() == "eth"){terminalView.println("Discovery: Using Ethernet as default interface.");- phy_interface = phy_interface_t::Eth;+ phy_interface = phy_interface_t::phy_eth;}else if (cmd.getSubcommand() == "wifi"){terminalView.println("Discovery: Using WiFi as default interface.");- phy_interface = phy_interface_t::WiFi;+ phy_interface = phy_interface_t::phy_wifi;}else {terminalView.println("Discovery: Invalid interface. Use 'wifi' or 'eth'.");}}- const std::string deviceIP = phy_interface == phy_interface_t::WiFi ? wifiService.getLocalIP() : ethernetService.getLocalIP();+ const std::string deviceIP = phy_interface == phy_interface_t::phy_wifi ? wifiService.getLocalIP() : ethernetService.getLocalIP();icmpService.startDiscoveryTask(deviceIP);}diff --git a/src/Services/ICMPService.cpp b/src/Services/ICMPService.cppindex be2773ac..bda3219f 100644--- a/src/Services/ICMPService.cpp+++ b/src/Services/ICMPService.cpp@@ -25,11 +25,13 @@ struct ICMPTaskParamsICMPService::ICMPService() {}-ICMPService::~ICMPService() {+ICMPService::~ICMPService()+{cleanupICMPService();}-void ICMPService::cleanupICMPService(){+void ICMPService::cleanupICMPService()+{// Reset last resultsready = false;ping_up = false;@@ -72,16 +74,49 @@ static int median_ms(std::vector<uint32_t> &v)return (int)((v[n / 2 - 1] + v[n / 2] + 1) / 2);}-void ICMPService::startDiscoveryTask(const std::string deviceIP){+void ICMPService::startDiscoveryTask(const std::string deviceIP)+{+ std::string deviceDiscoveryReport = "Discovery: scanning network for devices...\r\n";+ std::string deviceIPcopy = deviceIP;+ ip4_addr_t targetIP;+ TaskHandle_t pingTaskHandle = nullptr;++ if (!ip4addr_aton(deviceIPcopy.c_str(), &targetIP))+ {+ report = "Discovery: failed to parse IP address " + deviceIP + "\r\n";+ return;+ }+// Assume network mask is 255.255.255.0 for now-+ uint8_t deviceIndex = targetIP.addr & 0xFF;++ for (uint8_t targetIndex = 0; targetIndex < 255; targetIndex++)+ {+ char targetIPCStr[16];+ std::string targetIPStr;+ if (targetIndex == deviceIndex)+ continue;++ targetIP.addr = (targetIP.addr & 0xFFFFFF00) | targetIndex;+ // Convert numeric IP address into decimal dotted ASCII representation+ ip4addr_ntoa_r(&targetIP, targetIPCStr, sizeof(targetIPCStr));+ targetIPStr = std::string(targetIPCStr);++ this->cleanupICMPService();+ auto *params = new ICMPTaskParams{targetIPStr, 5, 1000, 200, this};+ xTaskCreatePinnedToCore(pingTask, "ICMPPing", 8192, params, 1, &pingTaskHandle, 1);+ while (!ready){+ vTaskDelay(pdMS_TO_TICKS(10));+ }+ deviceDiscoveryReport.append(report);+ }}void ICMPService::startPingTask(const std::string &host, int count, int timeout_ms, int interval_ms){// Cleanup firstthis->cleanupICMPService();-+auto *params = new ICMPTaskParams{host,count > 0 ? count : 5,timeout_ms > 0 ? timeout_ms : 1000,diff --git a/src/Services/ICMPService.h b/src/Services/ICMPService.hindex 4e3ab569..a996ecfc 100644--- a/src/Services/ICMPService.h+++ b/src/Services/ICMPService.h@@ -2,9 +2,9 @@#include <string>enum phy_interface_t {- None,- WiFi,- Eth+ phy_none,+ phy_wifi,+ phy_eth};class ICMPService {