You say that you want to get the MAC addresses of hosts when they plug into your network. One easy way to do this is to monitor the leases database maintained by your DHCP server. For example, the ISC's DHCP server (used in many Linux distros) maintains this information in an easy-to-parse text file. From the dhcpd.leases man page:
The Internet Software Consortium DHCP Server keeps a persistent database of leases that it has assigned. This database is a free-form ASCII file containing a series of lease declarations. Every time a lease is acquired, renewed or released, its new value is recorded at the end of the lease file. So if more than one declaration appears for a given lease, the last one in the file is the current one.
Thus you could use File::Tail or a similar means to monitor the leases file and act upon new leases as they appear. The typical lease entry looks like this:
lease 192.168.0.1 { starts 1 2004/09/27 14:16:02; ends 1 2004/09/27 15:16:02; hardware ethernet 00:0b:db:13:e7:49; }
Note the "hardware ethernet" field, which contains the MAC address of the host. You can easily grab this with a simple regex like /hardware\s+ethernet\s+([0-9a-f:]+);/i.

The nice thing about this approach is that you get a two-for-one bonus: When a host plugs into your network, you will receive instant notification of the fact via an addition to the leases database, and the notification will hand you the MAC address on a silver platter.

Hope this helps!

Cheers,
Tom


In reply to Re: getting mac address by tmoertel
in thread getting mac address by rhymejerky

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.