#!/usr/bin/perl

use Text::DHCPLeases;
     
my $leases = Text::DHCPLeases->new(file=>'/var/lib/dhcp/dhcpd.leases');

if (defined $ARGV[0]){
 my $param = $ARGV[0];
 my $n_dots = $param =~ tr/.//;
 my $n_colons = $param =~ tr/://;  

 my $it;
  
 if ($n_dots == 3) {
   $it = $leases->get_objects(ip_address=>$param);
 } elsif ($n_colons == 5) {
   $it =  $leases->get_objects(mac_address=>$param);
 }
 
 if (defined $it) {
   my $obj = $it->last;
   if (defined $obj) {
     print $obj->ip_address." ".$obj->mac_address." ".$obj->client_hostname;
     }
   }
 }
 
 