#!/usr/bin/perl $now = time(); use Time::Local; open(LEASE, "/var/lib/dhcp3/dhcpd.leases"); foreach $line () { chomp($line); $data = 1 if $line =~ /^lease /; $data = 0 if $line =~ /^}/; if ($data) { if ($line =~ /^lease/) { $ip = (split(" ", $line))[1]; } elsif ($line =~ /^ starts/) { ($date, $time) = (split(" ", $line))[2,3]; ($y, $m, $d) = split("/", $date); ($H, $M, $S) = split(":", $time); $start = timelocal($S,$M,$H,$d,$m,$y); } elsif ($line =~ /^ ends/) { ($date, $time) = (split(" ", $line))[2,3]; ($y, $m, $d) = split("/", $date); ($H, $M, $S) = split(":", $time); $stop = timelocal($S,$M,$H,$d,$m,$y); } elsif ($line =~ /^ hardware ethernet/) { $mac = (split(" ", $line))[2]; $mac =~ s/;//; } elsif ($line =~ /^ client-hostname/) { $client = (split(/\"/, $line))[1]; } } else { print localtime($start) . "\t" . localtime($stop) . "\t$ip\t$mac\t$client\n" if $stop >= $now; $ip = ""; $start = ""; $stop = ""; $mac = ""; $client = ""; } } close(LEASE);