Hi All,

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.


In reply to Problems with converting raw data to text by anderam

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.