problems parsing a DHCP.leases file.



Hi all,



I am having some problems filling a variable based on the contents of a
dhcpd.leases file. All I want at this time is the hostname and ip address.
My eventual goal is to create hash of hashes with this information but for
now I just want to read in the file and see that I have defined my variables
correctly. I am able to get the IP address but the $hostname variable is
always undefined. The syntax for any given host in a leases file looks like
this:



lease 10.10.97.207 {

starts 2 2005/12/20 16:10:51;

ends 2 2005/12/20 20:10:51;

tstp 2 2005/12/20 20:10:51;

binding state free;

hardware ethernet 00:0b:97:2b:ea:fe;

uid "\001\000\013\227+\352\376";

client-hostname "HOST1";

}



Here is what I have so far.



#!/usr/bin/perl

#

use strict;

use warnings;



my $dhcp_data = "dhcpd.leases";



my %dhcpd;

my $ip;

my $hostname;



{

open (DHCPD, $dhcp_data) || die "Can't open $dhcp_data $!\n";



while (my $line = <DHCPD>) {

next if ($line =~ /^\s*$/ or # blank line

$line =~ /^\s*#/ );



if ($line =~ /^lease (\d+\.\d+\.\d+\.\d+)/) {

$ip = $1; }

elsif ($line =~ /^client-hostname/) {

$hostname = $1; }

else {next;};

print "I found IP:$ip\n";

print "I found Hostname: $hostname\n";

}

}



Thanks,



-angus