#!/usr/bin/perl use strict; use Sort::Key::IPv4 qw(ipv4sort); open(TEXT,"dump.txt")or die("Text not found"); my %packets; while () { if ( /IP\s+(\d+\.\d+\.\d+\.\d+)(\.(\d+))?\s+>\s+(\d+\.\d+\.\d+\.\d++)(\.(\d+))?\:\s+(\w+)/ ) { my ($srcip, $srcport, $dstip, $dstport, $proto) = ($1, $3, $4, $6, $7); printf "%16s [%5d] --> %16s [%5d] (%s)\n", $srcip, $srcport, $dstip, $dstport, lc($proto); if ($srcport == $dstport) { # one IP to another on the same port... $packets{$srcport}{$srcip}{$dstip}++ } } } foreach my $port (sort { $a <=> $b } keys %packets) { # ports sorted ascending foreach my $srcip ( ipv4sort keys %{$packets{$port}}) { # source IPs sorted ascending foreach my $dstip ( ipv4sort keys %{$packets{$port}{$srcip}}) { # dest IPs sorted ascending print "On port $port, from $srcip to $dstip, there were $packets{$port}{$srcip}{$dstip} packets\n"; } } } }