in reply to Re^2: getting mac address
in thread getting mac address
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:
Hope this helps.#!/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 }
Cheers!
Tom
Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder
|
|---|