The approach I mentioned does require that the DHCP lease database be monitored. Most typically, you would use a long-running process (e.g., daemon) for this purpose, but you could also use a recurring job (a la cron) to scan the database every once in a while for changes. The daemon-based approach is probably simpler and will provide more immediate triggering of responses to newly plugged-in network devices, so that's the approach I will talk about below.
What I really want to do is trigger something and grab the user's MAC and see if the laptop is authorized. I know grab MAC address using ipconfig, but I want to automate this part.
The "trigger" is the appearance of a new entry in the DHCP leases database. The entry will contain the MAC address already, so there is no need to look it up using ipconfig.

For example, here is some (untested) code that monitors the lease database and triggers a call to check_authorization when a new lease record appears:

#!/usr/bin/perl use warnings; use strict; use File::Tail; # monitor the leases database, waiting for new entries my $leases_db = File::Tail->new("/var/lib/dhcp/dhcpd.leases"); # wait for entries of the following form: # # 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; # } while (defined( $_ = $leases_db->read )) { my $ip_addr = $1 if /^lease ([.0-9]+)/i; if (/hardware ethernet ([:0-9a-f]+)/i) { my $mac_addr = $1; check_authorization($ip_addr, $mac_addr); } } # the following subroutine will be called when a new # lease record appears in the DHCP server's database sub check_authorization { my ($ip_addr, $mac_addr) = @_; # look up $mac_addr in authorization database # and take action if necessary }
Hope this helps.

Cheers!
Tom


In reply to Re^3: 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.