-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleases.pl
executable file
·30 lines (27 loc) · 1005 Bytes
/
leases.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/perl
$now = time();
use Time::Local;
open(LEASE, "/var/lib/dhcp/dhcpd.leases");
foreach $line (<LEASE>) {
chomp($line);
$data = 1 if $line =~ /^lease /;
$data = 0 if $line =~ /^}/;
if ($data) {
if ($line =~ /^lease/) {
$ip = (split(" ", $line))[1];
} elsif ($line =~ /^ starts/) {
$start = (split(" ", $line))[2];
} elsif ($line =~ /^ ends/) {
$stop = (split(" ", $line))[2];
} elsif ($line =~ /^ hardware ethernet/) {
$mac = (split(" ", $line))[2];
$mac =~ s/;//;
} elsif ($line =~ /^ client-hostname/) {
$client = (split(/\"/, $line))[1];
}
} else {
print "$mac $ip\n" if $stop >= $now;
$ip = ""; $start = ""; $stop = ""; $mac = ""; $client = "";
}
}
close(LEASE);