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

Sébastien CRAMATTE s.cramatte at wanadoo.fr
Thu Jun 29 23:52:07 UTC 2006


mark a écrit :
> 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);
> }
>
>
>
>
>   
Hello,

But how do you parse the lease ?
Could you give me a complete example / script ?

Thanks


More information about the dhcp-users mailing list