anderam has asked for the wisdom of the Perl Monks concerning the following question:
I'm Perl newbie and I'm facing problem with $title. My script reads the pcap file using Net::Pcap and NetPacket. Script reads packet by packet, stripping them out of headers (Ethernet/IP/TCP) and takes only payload part. Then I don't know how to convert payload into readable text.
My code:
use Net::Pcap; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::TCP; use NetPacket::UDP; use NetPacket::ICMP; use strict; sub parsePayload { my($payload, $text) = @_; # now i don't know what to do my $data = pack("A",$payload); print "Data: $data\n"; } sub getPayload { my ($userdata, $header, $packet) = @_; my $ether_data = NetPacket::Ethernet::strip($packet); my $ip = NetPacket::IP->decode($ether_data); if ( $ip->{'proto'} == 6 ) { print "TCP\n"; my $l4 = NetPacket::IP::strip($ether_data); my $tcp = NetPacket::TCP->decode($l4); my $payload = $tcp->{'data'}; &parsePayload("$payload","$userdata"); } elsif ( $ip->{'proto'} == 17) { print "UDP\n"; my $l4 = NetPacket::IP::strip($ether_data); my $udp = NetPacket::UDP->decode($l4); my $payload = $udp->{'data'}; &parsePayload("$payload","$userdata"); } elsif ( $ip->{'proto'} == 1) { print "ICMP"; my $l4 = NetPacket::IP::strip($ether_data); my $icmp = NetPacket::ICMP->decode($l4); my $payload = $icmp->{'data'}; &parsePayload("$payload","$userdata"); } else { print "Unknown packet!\n"; } } my $err; my $pcap_t; $pcap_t = Net::Pcap::open_offline($ARGV[0],\$err); Net::Pcap::loop($pcap_t, 0, \&getPayload, 1); Net::Pcap::close($pcap_t); print "Done.\n";
Why do I want such a thing? I need to match regular expressions with payloads.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems with converting raw data to text
by bv (Friar) on Dec 06, 2009 at 15:02 UTC | |
by anderam (Initiate) on Dec 08, 2009 at 12:31 UTC | |
by bv (Friar) on Dec 08, 2009 at 16:55 UTC | |
|
Re: Problems with converting raw data to text
by Anonymous Monk on Dec 06, 2009 at 13:12 UTC | |
by anderam (Initiate) on Dec 06, 2009 at 14:08 UTC |