Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

418
Views
Linux C++ Cómo obtener mediante programación la dirección MAC para todos los adaptadores en una LAN

¿Cómo puedo usar el PROGRAMA C o C ++ (sin línea de comando) para obtener las direcciones MAC (también tomaré las direcciones IP si son "libres") en mi (pequeña) red local? Es un Busybox Linux incorporado, por lo que necesito una respuesta minimalista que, con suerte, no requiera la portabilidad de alguna biblioteca. No tengo libnet o libpcap. El caché arp parece no contener nunca nada más que el MAC si el servidor DHCP.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Fuente completa aquí.

Abra /proc/net/arp , luego lea cada línea así:

 char line[500]; // Read with fgets(). char ip_address[500]; // Obviously more space than necessary, just illustrating here. int hw_type; int flags; char mac_address[500]; char mask[500]; char device[500]; FILE *fp = xfopen("/proc/net/arp", "r"); fgets(line, sizeof(line), fp); // Skip the first line (column headers). while(fgets(line, sizeof(line), fp)) { // Read the data. sscanf(line, "%s 0x%x 0x%x %s %s %s\n", ip_address, &hw_type, &flags, mac_address, mask, device); // Do stuff with it. } fclose(fp);

Esto se tomó directamente de la implementación de arp de BusyBox, en busybox-1_21_0/networking/arp.c del tarball de BusyBox 1.21.0 . Mire la función arp_show() en particular.

Si tienes miedo de C:

El comando arp -a debería darle lo que desea, tanto direcciones MAC como direcciones IP.

Para obtener todas las direcciones MAC en una subred, puede intentar

 nmap -n -sP <subnet> arp -a | grep -v incomplete
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!