#!/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 }