jablonka.czprosek.czf

czfcentos

Subversion Repositories:
[/] [trunk/] [router/] [usr/] [local/] [bin/] [klc.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 
69print "Reading in $this_log...\n";
70 
71undef @this_log_lines;
72if ( $this_log =~ /.gz$/ ) {
73 die "Can't read $this_log without Compress::Zlib" unless $have_zlib;
74 my $gz = Compress::Zlib::gzopen($this_log,'r');
75 my $line;
76 while ( $gz->gzreadline($line) != 0 ) {
77 push @this_log_lines, $line;
78 }
79 $gz->gzclose;
80} else {
81 open(LOG_FILE, "$this_log");
82 @this_log_lines = <LOG_FILE>;
83 close(LOG_FILE);
84}
85 
86foreach $this_line (@this_log_lines) {
87$add_line = $this_line;
88 
89if ($this_line=~/<wireless-network number="\d\d"/) {
90$x++;
91$add_line =~ s/<wireless-network number="\d\d"/<wireless-network number="$x"/;
92} elsif ($this_line=~/<wireless-network number="\d"/) {
93$x++;
94$add_line =~ s/<wireless-network number="\d"/<wireless-network number="$x"/;
95}
96push (@new_lines, $add_line);
97} # end foreach $this_line
98} # end foreach $this_log
99 
100print "Writing out $out_file_name...\n";
101 
102open(OUT_FILE,">$out_file_name");
103foreach $out_line (@new_lines) {
104 
105if ($out_line=~/<?xml/) {
106print OUT_FILE ("$out_line") unless ($xml_start);
107$xml_start = 1;
108}
109elsif ($out_line=~/<!DOCTYPE/) {
110print OUT_FILE ("$out_line") unless ($doc_start);
111$doc_start = 1;
112}
113elsif ($out_line=~/<detection-run/) {
114print OUT_FILE ("$out_line") unless ($run_start);
115$run_start = 1;
116}
117elsif ($out_line=~/<\/detection-run/) {
118}
119elsif ($out_line =~/^\n/) {
120}
121else {
122print OUT_FILE ("$out_line");
123}
124} # end foreach $out_line
125print OUT_FILE ("<\/detection-run>\n");
126close(OUT_FILE);

Powered by WebSVN 2.2.1