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:
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.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; }
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
Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder
In reply to Re: getting mac address
by tmoertel
in thread getting mac address
by rhymejerky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |