Note, your code as stated above, does not compile.

You did not state the format of the log file, so I created my own :) Here is code to do roughly what you want:

my @trojan_ports = (113, 15118, 4899); my %trojan; @trojan{@trojan_ports} = 1; my @win_ports = (135, 137, 139, 445, 1025, 1433, 1434); my %win; @win{@win_ports} = 1; my %port_ip; while (<DATA>) { chomp; my ($ip, $port) = split m"/"; push @{ $port_ip{$port} }, $ip; } foreach my $port (sort {$a <=> $b} keys %port_ip) { if (exists $win{$port}) { print "Windows port $port\n"; } elsif (exists $trojan{$port}) { print "Trojan port $port\n"; } else { print "Unknown port $port\n"; } print " $_\n" foreach @{ $port_ip{$port} }; } __DATA__ 1.2.3.4/135 1.2.3.5/135 1.2.3.6/135 1.2.3.4/137 1.2.3.7/137 1.2.3.9/113 1.2.3.10/111

-Mark


In reply to Re: Firewall Log Analysis - port matrices by kvale
in thread Firewall Log Analysis - port matrices by monger

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.