NAME
Text::DHCPparse - Perl extension for parsing dhcpd lease files
SYNOPSIS
use Text::DHCPparse;
DESCRIPTION
The basic premise of the Text::DHCPparse module is to parse the lease file from an ISC DHCPd server. This is useful for quick reporting on active leases or for tracking purposes. The resulting hash reference is a fixed length record with the key being the IP address for the lease, and the value being the lease info in the following format:
Characters Field
---------- --------------------
1 - 17 IP Address
18 - 38 Last Lease Timestamp
39 - 57 Hardware Address
58 - 74 Client Hostname
The following is if you are using the no colon function: Characters Field ---------- -------------------- 1 - 17 IP Address 18 - 38 Last Lease Timestamp 39 - 52 Hardware Address 53 - 69 Client Hostname
(All fields have a minimum 2-space field delimiter for formatting.)
WARNING: Always use a copy of your 'dhcpd.leases' file - never use an original from a live server!
The following is a simple piece of code to show the functionality of the Text::DHCPparse module:
#!/usr/bin/perl
use Text::DHCPparse;
$return = leaseparse('/tmp/dhcpd.leases');
foreach (keys %$return) {
print "$return->{$_}\n";
}
The following code can be used to take the output from Text::DHCPparse and separate it into individual fields if you don't like the fixed length record:
#!/usr/bin/perl
use Text::DHCPparse;
$return = leaseparse('/tmp/dhcpd.leases');
foreach (keys %$return) {
($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30", $return->{$_});
# code to handle the '$ip $time $mac & $name' variables
}
The exported function leaseparsenc works exactly the same, but it removed colons from the MAC address and shortens the record by 5 characters.
AUTHOR
John D. Shearer <jds@jkshearer.com>
SEE ALSO
perl(1).
COPYRIGHT
Copyright (c) 2001 John D. Shearer. All rights reverved. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.