#!/usr/bin/perl -w # a tool for parsing ISC DHCP server logs. # outline: # read entries into a tree, grouped by # MAC address, # IP address, # DHCP protocol message type ( 'RELEASE' 'REQUEST' 'OFFER' 'ACK' ...) # ...and print this out use strict; use CGI qw/:standard -no_xhtml/; use Data::Dumper; $|=1; my $MYNAME="current dhcpd log for " . `hostname`; my $makufa; #my $logfile="/var/log/messages"; my $logfile="/var/log/dhcpd/current"; open MESS, $logfile or die "can't open logfile $logfile"; while () { next unless /DHCP(\w+).* (\d+\.\d+\.\d+\.\d+) .* (..:..:..:..:..:..)/; my($dhcptype,$ip,$mac) = ($1,$2,$3); $makufa->{$mac}->{$ip}->{$dhcptype}++; }; close MESS; #warn "did not print anything yet"; my @arp=`/sbin/arp`; for my $mac ( keys %{$makufa} ) { for my $line ( @arp ) { if ( $line =~ /$mac/i ) { $makufa->{$mac}->{'arp'} = $line; last; } } } my $count = scalar keys %{$makufa}; print header, start_html($MYNAME), p("First line:\n" , `head -n 1 $logfile | /usr/local/bin/tai64nlocal`), h4("Total of $count MAC addresses"), pre( Dumper($makufa) ), end_html; warn "$MYNAME has been executed\n"; 1;