I need to parse dhcpd.leases to store data in mysql

mark mark at immermail.com
Wed Jun 28 20:45:35 UTC 2006


Sébastien CRAMATTE wrote:
> Hello,
> 
> I need to parse the  dhcpd.leases files to store result in mysql database
> I use option 82 and few other advanced features.
> 
> I've found this project that normally do what I need :  
> http://lease-parser.sourceforge.net/
> After somme hours ant lots of tricks  it seems to works  on my debian 
> sarge ...
> But I don't like this approach!
> 
> So If anyone have an alternative  solution based on perl  script and php  ?
> Thanks for your help

Not much to it really.  I do something like:


$insert = $dbh->prepare("insert into LEASES (STARTS, ENDS, STATE, MAC) 
values (?,?,?,?)");

$/ = "}\n";
while (<>) {
     ($starts) = /starts \d ([^;]+)/;
     ($ends) = /starts \d ([^;]+)/;
     ($state) = /binding state ([^;]+)/;
     ($mac) = /hardware ethernet ([^;]+)/;

     $insert->execute($starts, $ends, $state, $mac);
}


More information about the dhcp-users mailing list