#!/usr/bin/perl
# This script is intended to produce a table like below:
#
# [root@sky Cisco-related]# ./dhcpd_conf2table.pl < dhcpd.conf
#
# 1       08:00:20:1b:34:3d       0800.201b.343d  212.16.26.25
# 2       00:03:e3:ac:ba:80       0003.e3ac.ba80  cisco29.misis.ru
#
# Works only for some dhcpd.conf - when host definitions are 1 per line - just
# made for mtcm.ru configs.
#
# License is current GNU one.
# (c) Light Olli <olli@digger.org.ru>
#
$counter=0;
while(<STDIN>)
{
 $string=$_;
 next unless /hardware\s+ethernet\s+([a-f\d]?[a-f\d]):([a-f\d]?[a-f\d]):([a-f\d]?[a-f\d]):([a-f\d]?[a-f\d]):([a-f\d]?[a-f\d]):([a-f\d]?[a-f\d])\s*\;/i;
 $newmacnot="$1$2.$3$4.$5$6"; $oldmacnot="$1:$2:$3:$4:$5:$6";
 $counter++;
 print "\n$counter\t$oldmacnot\t$newmacnot";
 if (/fixed\-address\s+([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\s*\;/)
  {print "\t$1.$2.$3.$4";}
 else 
  {if (/fixed\-address\s+(\S+\.?\S+)\s*;\s*/)
    {print "\t$1";}
   else 
    {print "\n";}
  }
 next;
}
print "\n";