Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <lilka.h>
- #include "ipapp.h"
- #include "servicemanager.h"
- #include "services/network.h"
- extern "C" {
- #include "lwip/etharp.h"
- #include "lwip/netif.h"
- #include "lwip/ip_addr.h"
- }
- IPApp::IPApp() : App("IP Address") {}
- void IPApp::scanNetwork(std::vector<String>& results) {
- struct netif* netif = netif_list;
- IPAddress localIP = WiFi.localIP();
- uint8_t subnet[4] = { localIP[0], localIP[1], localIP[2], 0 };
- // Відправляємо ARP-запити до всіх адрес у підмережі
- for (int i = 1; i <= 254; ++i) {
- ip4_addr_t target_ip;
- subnet[3] = i;
- IPAddress ip(subnet[0], subnet[1], subnet[2], subnet[3]);
- ip4addr_aton(ip.toString().c_str(), &target_ip);
- etharp_request(netif, &target_ip);
- vTaskDelay(10 / portTICK_PERIOD_MS);
- }
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- // Збираємо знайдені IP–MAC
- for (int i = 1; i <= 254; ++i) {
- subnet[3] = i;
- IPAddress ip(subnet[0], subnet[1], subnet[2], subnet[3]);
- ip4_addr_t target_ip;
- ip4addr_aton(ip.toString().c_str(), &target_ip);
- struct eth_addr *eth_ret;
- const ip4_addr_t *ip_ret;
- if (etharp_find_addr(netif, &target_ip, ð_ret, &ip_ret) >= 0) {
- char macbuf[18];
- snprintf(macbuf, sizeof(macbuf), "%02X:%02X:%02X:%02X:%02X:%02X",
- eth_ret->addr[0], eth_ret->addr[1], eth_ret->addr[2],
- eth_ret->addr[3], eth_ret->addr[4], eth_ret->addr[5]);
- results.push_back(ip.toString() + " - " + String(macbuf));
- }
- }
- }
- void IPApp::run() {
- std::vector<String> arpResults;
- scanNetwork(arpResults);
- lilka::Menu menu("ARP scan");
- menu.addActivationButton(lilka::Button::B); // Back
- if (arpResults.empty()) {
- menu.addItem("No devices found");
- } else {
- for (const auto& entry : arpResults) {
- menu.addItem(entry);
- }
- }
- menu.addItem("Назад");
- int count = (int)arpResults.size() + 1;
- if (arpResults.empty()) count = 2;
- while (true) {
- while (!menu.isFinished()) {
- menu.update();
- menu.draw(canvas);
- queueDraw();
- }
- int cursor = menu.getCursor();
- if (cursor == count - 1 || menu.getButton() == lilka::Button::B) {
- return;
- }
- // Якщо вибрано "No devices found" — просто оновити меню (нічого не робимо)
- }
- }
- #ifndef IPAPP_H
- #define IPAPP_H
- #include <lilka.h>
- #include "app.h"
- #include "services/network.h"
- #include <vector>
- class IPApp : public App {
- public:
- IPApp();
- private:
- void run() override;
- void scanNetwork(std::vector<String>& results);
- lilka::Menu menu;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement