Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Here's what I've come up with so far. Basically I iterate over each packet and generate substrings from size 2 to the size of the packet. I then compare that against all of the other packets. It needs some tweaking in that area, but I get output that makes sense. Only problem is that on my machine, running it with large packets kills the OS after an hour or so. Apparently I need to make some memory optimizations somewhere. All comments are appreciated! Windows environ - no #!
die "No file name" unless @ARGV; my @packets = (); while (<>) { push(@packets,$_); } chop(@packets); my $maxlen =0; my $index = 0; my $curpack; my %all; # iterate over all packets foreach $curpack (@packets) { $maxlen = length($curpack); # substring size for (my $fsize = 2; $fsize < $maxlen; $fsize ++) { # packet to compare against for (my $pnum = 0; $pnum < @packets; $pnum ++) { # start substr'ing at index 0 for (0..$maxlen-$fsize) { # don't compare against self if ($index != $pnum) { my $str = substr($curpack,$_,$fsize); my @temparr = ($packets[$pnum] =~ /$str/g); my $nmatch = @temparr; if (defined($all{$str})) { $all{$str} += $nmatch; } else { $all{$str} = $nmatch; } undef @temparr; } } } } $index ++; # print results for current packet print "Comparing packet ",$index," to all others:\n"; my $value; my @sort = sort {length($b) <=> length($a)} keys %all; foreach $value (@sort) { if ($all{$value} > 0) { print "$value: $all{$value} times\n"; } delete($all{$value}); } undef @sort; } exit;

In reply to (Guildenstern) Re: Finding patterns (prelim code) by Guildenstern
in thread Finding patterns in packet data? by Guildenstern

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.