#! /usr/bin/perl -w # # Copyright (C) 2005 -- Nicolas Bareil (nbareil @ mouarf.org) # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. use strict; use GD::Simple; use XML::Simple; use Data::Dumper; use Date::Parse; use constant { HAUTEUR_TRAIT => 5, X_SIZE => 400, Y_SIZE => 100, MARGE => 10, }; # Fri, 04 Mar 2005 16:06:43 +0100 my ($xml, @networks, $img, $need_to_sort_by_date); my ($starttime, $interval, $endtime, $wep_enabled); my ($opt_pngfile, $wep_disabled); $wep_enabled = "limegreen"; $wep_disabled = "red"; $need_to_sort_by_date =01; if ($#ARGV + 1 >= 2) { $xml = XMLin($ARGV[0]); $opt_pngfile = $ARGV[1]; } else { usage(); exit(-1); } if (not defined $xml) { print STDERR "Cannot parse XML file !\n"; exit(-1); } @networks = map { $_->{'first-time'} = str2time($_->{'first-time'}); $_->{'last-time'} = str2time($_->{'last-time'}); $_; } @{$xml->{'wireless-network'}}; $endtime = str2time($xml->{'end-time'}); $starttime = str2time($xml->{'start-time'}); $interval = ($endtime - $starttime) / $#networks; if ($need_to_sort_by_date) { @networks = sort {$a->{'first-time'} >= $b->{'first-time'}} @networks } init_graph(\@networks); for my $wlan (@networks) { graph_wlan($wlan); } save_pngfile(); # --------------------------------------------------------------------------- sub usage { print <<"EOF"; viewkismetlogs -- analyse Kismet (xml) logs in function of time and create a picture usage: % viewkismetlogs /var/log/kismet/Kismet-1.xml wlan.png EOF } sub init_graph { my $networks = shift; $img = GD::Simple->new($endtime - $starttime, Y_SIZE); $img->clear(); $img->fgcolor($wep_enabled); $img->moveTo(($endtime - $starttime) - 90, Y_SIZE - 20); $img->line(4); $img->moveTo(($endtime - $starttime) - 80, Y_SIZE - 15); $img->string('wep enabled'); $img->fgcolor($wep_disabled); $img->moveTo(($endtime - $starttime) - 90, Y_SIZE - 5); $img->line(4); $img->moveTo(($endtime - $starttime) - 80, Y_SIZE); $img->string('wep disabled'); $img->fgcolor('gray'); $img->bgcolor('white'); $img->moveTo(10, 20); $img->string('From ' . localtime($starttime) . ' to ' . localtime($endtime)); $img->moveTo(MARGE, Y_SIZE/2); $img->line(($endtime - $starttime) - 2*MARGE); $img->turn(90); graph_rule(); $img->fgcolor('blue'); } sub graph_rule { my $i = 0; while ($i < ($endtime - $starttime) - MARGE) { for my $j (0..1) { $img->moveTo($i+MARGE+$j, Y_SIZE/2 - HAUTEUR_TRAIT/2); $img->line(0, HAUTEUR_TRAIT); } $img->moveTo($i + MARGE - 10, Y_SIZE/2 + 4*HAUTEUR_TRAIT); $img->string($i/60 . "mn"); $i += 60; } } sub graph_wlan { my $wlan = shift; my $x = ($endtime - $wlan->{'first-time'}); $img->fgcolor($wlan->{'wep'} eq 'true' ? $wep_enabled : $wep_disabled); $img->moveTo(MARGE + $x, Y_SIZE/2 - HAUTEUR_TRAIT); $img->line(0, 2 * HAUTEUR_TRAIT); } sub save_pngfile { open PNGFILE, "> $opt_pngfile" or die $!; print PNGFILE $img->png; close PNGFILE or die $!; }