jablonka.czprosek.czf

czfcentos

Subversion Repositories:
[/] [trunk/] [router/] [usr/] [local/] [bin/] [klcs.pl] - Blame information for rev 3

 

Line No. Rev Author Line
13czfcentos#!/usr/bin/perl
2##########################################################################################################
3#
4# Kismet Log Combiner (part of Kismet Log Viewer) - By Brian Foy Jr. - 3/26/2003
5#
6# Takes multiple Kismet .xml log files and Outputs one new .xml file with the networks renumbered.
7#
8# Requires:
9# At leaast two Kismet .xml logfiles.
10#
11# To Use:
12# ./klc.pl Kismet-Log1.xml Kismet-Log2.xml Kismet-Log3.xml New-Kismet-Comb-Log.xml
13# ./klc.pl *.xml New-Kismet-Comb-Log.xml
14# ./klc.pl ./klc.pl *.xml.gz New-Kismet-Comb-Log.xml
15#
16# Optional:
17# If you have the .dump files for the .xml files and also want to combine those, you can
18# add -dump to the end. This will create a .dump file with the same output name.
19# Example:
20# ./klc.pl *.xml New-Kismet-Comb-Log.xml -dump
21#
22##########################################################################################################
23 
24my $have_zlib = 0;
25if ( eval "require Compress::Zlib" ) {
26 $have_zlib = 1;
27}
28 
29if (@ARGV < 2) {
30 print "Usage: $0 <list> <of> <log> <files> <to> <combine> output-file-name.xml [-dump]\n";
31 exit;
32}
33 
34 
35$check_for_dump = pop @ARGV;
36 
37if ( "$check_for_dump" eq "-dump" ) {
38$out_file_name = pop @ARGV;
39$do_dump = 1;
40print "got dump\n";
41} else {
42$out_file_name = $check_for_dump;
43}
44 
45@log_files = @ARGV;
46 
47if ($do_dump) {
48 
49# mergecap -w out.dump test.dump test2.dump
50$dump_out_file_name = $out_file_name;
51$dump_out_file_name =~ s/\.xml/\.dump/g;
52$run_merge_cap = "mergecap -w $dump_out_file_name ";
53@dump_files = @log_files;
54 
55 foreach $this_dump_file (@dump_files) {
56 $this_dump_file =~ s/\.xml/\.dump/g;
57 $run_merge_cap .= "$this_dump_file ";
58 }
59 
60print "Merging .dump files using: $run_merge_cap\n";
61system ("$run_merge_cap");
62}
63 
64 
65$x = 0;
66 
67foreach $this_log (@log_files) {
68 
69$this_csv_file = $this_log;
70$this_csv_file =~ s/\.xml/\.csv/g;
71open(CSV_FILE, "$this_csv_file");
72@this_csv_lines = <CSV_FILE>;
73close(CSV_FILE);
74$this_csv_line = shift(@this_csv_lines);
75 
76print "Reading in $this_log...\n";
77 
78undef @this_log_lines;
79if ( $this_log =~ /.gz$/ ) {
80 die "Can't read $this_log without Compress::Zlib" unless $have_zlib;
81 my $gz = Compress::Zlib::gzopen($this_log,'r');
82 my $line;
83 while ( $gz->gzreadline($line) != 0 ) {
84 push @this_log_lines, $line;
85 }
86 $gz->gzclose;
87} else {
88 open(LOG_FILE, "$this_log");
89 @this_log_lines = <LOG_FILE>;
90 close(LOG_FILE);
91}
92 
93foreach $this_line (@this_log_lines) {
94$add_line = $this_line;
95 
96if ($this_line=~/channel/) {
97 push (@new_lines, $add_line);
98 $this_csv_line = shift(@this_csv_lines);
99 @this_csv_line_values = split(";",$this_csv_line);
100 $this_csv_line_quality = splice( @this_csv_line_values,21,1);
101 $this_csv_line_signal = splice( @this_csv_line_values,21,1);
102 $this_csv_line_noise = splice( @this_csv_line_values,21,1);
103 push (@new_lines, "<quality>$this_csv_line_quality</quality>\n");
104 push (@new_lines, "<signal>$this_csv_line_signal</signal>\n");
105 push (@new_lines, "<noise>$this_csv_line_noise</noise>\n");
106} else {
107 if ($this_line=~/<wireless-network number="\d\d"/) {
108 $x++;
109 $add_line =~ s/<wireless-network number="\d\d"/<wireless-network number="$x"/;
110 } elsif ($this_line=~/<wireless-network number="\d"/) {
111 $x++;
112 $add_line =~ s/<wireless-network number="\d"/<wireless-network number="$x"/;
113 }
114 push (@new_lines, $add_line);
115}
116 
117} # end foreach $this_line
118} # end foreach $this_log
119 
120print "Writing out $out_file_name...\n";
121 
122open(OUT_FILE,">$out_file_name");
123foreach $out_line (@new_lines) {
124 
125if ($out_line=~/<?xml/) {
126print OUT_FILE ("$out_line") unless ($xml_start);
127$xml_start = 1;
128}
129elsif ($out_line=~/<!DOCTYPE/) {
130print OUT_FILE ("$out_line") unless ($doc_start);
131$doc_start = 1;
132}
133elsif ($out_line=~/<detection-run/) {
134print OUT_FILE ("$out_line") unless ($run_start);
135$run_start = 1;
136}
137elsif ($out_line=~/<\/detection-run/) {
138}
139elsif ($out_line =~/^\n/) {
140}
141else {
142print OUT_FILE ("$out_line");
143}
144} # end foreach $out_line
145print OUT_FILE ("<\/detection-run>\n");
146close(OUT_FILE);

Powered by WebSVN 2.2.1