#!/usr/bin/perl
# Run with some command like:
# tcpdump -n -x -s 32000 -i eth1 'port 1863 and host 192.168.27.140' | ./parser.pl
#
# replacing eth1 and the ip; of course.

my $t = '';
my $d='';
$|++;

while(<>) {
        if(/^\d/) {
                $t =~ s/^(.*)\n//;
                my $v = $1;
                $t =~ s/\n//g;
                $t =~ s/\s+//g;
                $t =~ s/(.{2})/chr hex $1/eig or goto END;
                $t =~ s/^.{40}//sg or goto END;
                $t =~ s/[\x00-\x09\x0B-\x1F\x80-\xFF]//g;
                chomp $t;
                $t or goto END;

#               if($t !~ /TypingUser/ and $t =~ /^MSG (\S+)/) {
#                       my $u = " $1";
#                       $u !~ /@/ and $u = '';
#                       my $m = (split /\n\n/, $t, 2)[1];
#                       print "$d$u: $m\n";
#               }

                print "$t\n";
END:            $t = '';
        }
        $d = join ':', (localtime)[2,1,0];

        $t .= $_;
}
