#!/usr/bin/perl ########################################################################################################## # # Kismet Log Combiner (part of Kismet Log Viewer) - By Brian Foy Jr. - 3/26/2003 # # Takes multiple Kismet .xml log files and Outputs one new .xml file with the networks renumbered. # # Requires: # At leaast two Kismet .xml logfiles. # # To Use: # ./klc.pl Kismet-Log1.xml Kismet-Log2.xml Kismet-Log3.xml New-Kismet-Comb-Log.xml # ./klc.pl *.xml New-Kismet-Comb-Log.xml # ./klc.pl ./klc.pl *.xml.gz New-Kismet-Comb-Log.xml # # Optional: # If you have the .dump files for the .xml files and also want to combine those, you can # add -dump to the end. This will create a .dump file with the same output name. # Example: # ./klc.pl *.xml New-Kismet-Comb-Log.xml -dump # ########################################################################################################## my $have_zlib = 0; if ( eval "require Compress::Zlib" ) { $have_zlib = 1; } if (@ARGV < 2) { print "Usage: $0 output-file-name.xml [-dump]\n"; exit; } $check_for_dump = pop @ARGV; if ( "$check_for_dump" eq "-dump" ) { $out_file_name = pop @ARGV; $do_dump = 1; print "got dump\n"; } else { $out_file_name = $check_for_dump; } @log_files = @ARGV; if ($do_dump) { # mergecap -w out.dump test.dump test2.dump $dump_out_file_name = $out_file_name; $dump_out_file_name =~ s/\.xml/\.dump/g; $run_merge_cap = "mergecap -w $dump_out_file_name "; @dump_files = @log_files; foreach $this_dump_file (@dump_files) { $this_dump_file =~ s/\.xml/\.dump/g; $run_merge_cap .= "$this_dump_file "; } print "Merging .dump files using: $run_merge_cap\n"; system ("$run_merge_cap"); } $x = 0; foreach $this_log (@log_files) { $this_csv_file = $this_log; $this_csv_file =~ s/\.xml/\.csv/g; open(CSV_FILE, "$this_csv_file"); @this_csv_lines = ; close(CSV_FILE); $this_csv_line = shift(@this_csv_lines); print "Reading in $this_log...\n"; undef @this_log_lines; if ( $this_log =~ /.gz$/ ) { die "Can't read $this_log without Compress::Zlib" unless $have_zlib; my $gz = Compress::Zlib::gzopen($this_log,'r'); my $line; while ( $gz->gzreadline($line) != 0 ) { push @this_log_lines, $line; } $gz->gzclose; } else { open(LOG_FILE, "$this_log"); @this_log_lines = ; close(LOG_FILE); } foreach $this_line (@this_log_lines) { $add_line = $this_line; if ($this_line=~/channel/) { push (@new_lines, $add_line); $this_csv_line = shift(@this_csv_lines); @this_csv_line_values = split(";",$this_csv_line); $this_csv_line_quality = splice( @this_csv_line_values,21,1); $this_csv_line_signal = splice( @this_csv_line_values,21,1); $this_csv_line_noise = splice( @this_csv_line_values,21,1); push (@new_lines, "$this_csv_line_quality\n"); push (@new_lines, "$this_csv_line_signal\n"); push (@new_lines, "$this_csv_line_noise\n"); } else { if ($this_line=~/$out_file_name"); foreach $out_line (@new_lines) { if ($out_line=~/\n"); close(OUT_FILE);