Skip to content

Commit

Permalink
added telnet, ssh and arp
Browse files Browse the repository at this point in the history
  • Loading branch information
pr3y committed May 9, 2024
1 parent f8b6337 commit 7179e3d
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 3 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib_deps =
WireGuard-ESP32
IRremoteESP8266
Time
LibSSH-ESP32
; bodmer/TFT_eSPI@^2.5.43 ; Esta biblioteca deve estar na pasta lib, devido as alterações no drive do StickC


Expand Down
93 changes: 93 additions & 0 deletions src/arp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "lwip/opt.h"
#include "esp_eth.h"
#include "lwip/etharp.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "nvs_flash.h"
#include "lwip/pbuf.h"
#include "lwip/netif.h"
#include "lwip/ip_addr.h"
#include "lwip/ethip6.h"
#include "lwip/ip.h"
#include "lwip/ip4_addr.h"
#include "lwip/prot/udp.h"
#include "display.h"
#include "globals.h"
#include "arp.h"

// #define ARP_TABLE_SIZE 30 // TODO: this probably is causing inconsistance


int etharp_get_entry(size_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_addr **eth_ret);


void print_arp_table() {
struct netif *existing_netif = netif_default;

if (existing_netif != NULL) {
ip4_addr_t *printed_addresses[ARP_TABLE_SIZE];
memset(printed_addresses, 0, sizeof(printed_addresses));

for (int i = 0; i < ARP_TABLE_SIZE; i++) {
ip4_addr_t *ipaddr;
struct netif *netif_entry;
struct eth_addr *eth_ret;

int result = etharp_get_entry(i, &ipaddr, &netif_entry, &eth_ret);
delay(1000);

if (result == 0 && ipaddr != NULL) {
// Check if the IP address has already been printed
int is_duplicate = 0;
for (int j = 0; j < ARP_TABLE_SIZE; j++) {
if (printed_addresses[j] != NULL && ip4_addr_cmp(ipaddr, printed_addresses[j])) {
is_duplicate = 1;
break;
}
}

if (!is_duplicate) {
Serial.print("IP: ");
Serial.print(ip4addr_ntoa(ipaddr));
tft.println(ip4addr_ntoa(ipaddr));
Serial.print("\tMAC: ");

char mac_str[18];
snprintf(mac_str, sizeof(mac_str), "%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]);

Serial.print(mac_str);
Serial.println();

for (int j = 0; j < ARP_TABLE_SIZE; j++) {
if (printed_addresses[j] == NULL) {
printed_addresses[j] = ipaddr;
break;
}
}
}
}
}
} else {
Serial.println("No network interface available.");
}
delay(1000);
tft.fillScreen(TFT_BLACK);
}

void local_scan_setup() {
tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);

Serial.printf("starting ARP scan");

tft.setTextColor(TFT_DARKGREEN, BGCOLOR);
tft.println(WiFi.localIP().toString().c_str());
tft.setTextColor(FGCOLOR, BGCOLOR);
print_arp_table();

}

8 changes: 8 additions & 0 deletions src/arp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#include <WiFi.h>

int etharp_get_entry(size_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_addr **eth_ret);

void local_scan_setup();

void print_arp_table();
Loading

0 comments on commit 7179e3d

Please sign in to comment.