macaddress.pl

This perl script collects MAC addresses on a local ethernet-based IP network. It does this by sending ICMP ECHO packets asynchronously to the specified range of addresses, and then picks up the ARP cache by running arp -a after waiting for replies.

If I recall correctly, this was the first program I wrote that uses raw sockets.

Source code: macaddress.pl.

When calling macaddress as a CGI script, a setuid-root wrapper is needed to give the Perl process enough privileges for handling raw sockets. Here is the wrapper I use. Compile it and do: chown root macaddress && chmod 4711 macaddress.

#include <unistd.h>
#include <stdio.h>
#define PROGRAM_PATH "/usr/local/bin/macaddress.pl"

main(int argc, char *argv[]) {
    argv[1] = 0;
    execvp(PROGRAM_PATH, argv);
    fprintf(stderr, "%s: exec failed.\n", argv[0]);
    exit(1);
}