| 1 | package Net::Analysis::Listener::Example2; | ||
| 2 | # $Id: Example2.pm 143 2005-11-03 17:36:58Z abworrall $ | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use base qw(Net::Analysis::Listener::Base); | ||
| 7 | |||
| 8 | sub tcp_monologue { | ||
| 9 | my ($self, $args) = @_; | ||
| 10 | my ($mono) = $args->{monologue}; # isa Net::Analysis::TCPMonologue | ||
| 11 | my ($pkt) = $mono->first_packet(); # isa Net::Analysis::Packet | ||
| 12 | my ($from) = $pkt->{from}; | ||
| 13 | my ($time) = $pkt->{time}->as_string('full'); | ||
| 14 | |||
| 15 | printf "(%s) %-22.22s % 6d bytes", $time, $from, $mono->length(); | ||
| 16 | |||
| 17 | if ($self->{regex}) { | ||
| 18 | if ($mono->data() =~ /(.{0,10}$self->{regex}.{0,10})/i) { | ||
| 19 | print " ** regex matched: '$1'"; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | print "\n"; | ||
| 24 | } | ||
| 25 | |||
| 26 | 1; | ||
| 27 | |||
| 28 | =head1 NAME | ||
| 29 | |||
| 30 | Net::Analysis::Listener::Example2 - accessing TCP info | ||
| 31 | |||
| 32 | =head1 SYNOPSIS | ||
| 33 | |||
| 34 | package Net::Analysis::Listener::Example2; | ||
| 35 | |||
| 36 | use strict; | ||
| 37 | use warnings; | ||
| 38 | use base qw(Net::Analysis::Listener::Base); | ||
| 39 | |||
| 40 | sub tcp_monologue { | ||
| 41 | my ($self, $args) = @_; | ||
| 42 | my ($mono) = $args->{monologue}; # isa Net::Analysis::TCPMonologue | ||
| 43 | my ($pkt) = $mono->first_packet(); # isa Net::Analysis::Packet | ||
| 44 | my ($from) = $pkt->{from}; | ||
| 45 | my ($time) = $pkt->{time}->as_string('full'); | ||
| 46 | |||
| 47 | printf "(%s) %-22.22s % 6d bytes", $time, $from, $mono->length(); | ||
| 48 | |||
| 49 | if ($self->{regex}) { | ||
| 50 | if ($mono->data() =~ /(.{0,10}$self->{regex}.{0,10})/i) { | ||
| 51 | print " ** regex matched: '$1'"; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | print "\n"; | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; | ||
| 59 | |||
| 60 | You can invoke this example on a TCP capture file from the command line, as | ||
| 61 | follows: | ||
| 62 | |||
| 63 | $ perl -MNet::Analysis -e main Example2,regex=img t/t1_google.tcp | ||
| 64 | |||
| 65 | Note the regex parameter being passed to the Example2 listener. | ||
| 66 | |||
| 67 | =head1 DESCRIPTION | ||
| 68 | |||
| 69 | This Listener prints a brief summary of the monologue traffic, and | ||
| 70 | optionally greps the monologue data for a regex, if one is passed | ||
| 71 | via config into $self. | ||
| 72 | |||
| 73 | =head1 SEE ALSO | ||
| 74 | |||
| 75 | L<Net::Analysis>. | ||
| 76 | |||
| 77 | =head1 AUTHOR | ||
| 78 | |||
| 79 | Adam B. Worrall, E<lt>worrall@cpan.orgE<gt> | ||
| 80 | |||
| 81 | =head1 COPYRIGHT AND LICENSE | ||
| 82 | |||
| 83 | Copyright (C) 2004 by Adam B. Worrall | ||
| 84 | |||
| 85 | This library is free software; you can redistribute it and/or modify | ||
| 86 | it under the same terms as Perl itself, either Perl version 5.8.5 or, | ||
| 87 | at your option, any later version of Perl 5 you may have available. | ||
| 88 | |||
| 89 | =cut |