Hi

I have some code to analyze a pcap (see below). Besides src-ip dest-ip src-mac dst-mac what I need to ID it type of packet HTTP arp icmp etc

print $ip_obj->{proto}, ",", $eth_obj->{type} gives me something like

6,2048 how would I translate that into a meaninfull application layer name like HTTP HTTPS FTP etc...

#!/usr/bin/perl -w use Exporter; use Net::TcpDumpLog; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::TCP; use strict; use warnings; #@ISA = qw(Exporter); print "0\n"; my $log = Net::TcpDumpLog->new(); $log->read("/mnt/pcaps/pcap_2011-05-27-03:00:01.pcap"); print "1\n"; foreach my $index ($log->indexes) { print "2\n"; my ($length_orig, $length_incl, $drops, $secs, $msecs) = $log->heade +r($index); my $data = $log->data($index); my $eth_obj = NetPacket::Ethernet->decode($data); next unless $eth_obj->{type} == NetPacket::Ethernet::ETH_TYPE_IP; my $ip_obj = NetPacket::IP->decode($eth_obj->{data}); next unless $ip_obj->{proto} == NetPacket::IP::IP_PROTO_TCP; my $tcp_obj = NetPacket::TCP->decode($ip_obj->{data}); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime +($secs + $msecs/1000); print sprintf("%02d-%02d %02d:%02d:%02d.%d", $mon, $mday, $hour, $mi +n, $sec, $msecs), " ", $eth_obj->{src_mac}, " -> ", $eth_obj->{dest_m +ac}, "\n"; print $ip_obj->{proto}, ",", $eth_obj->{type}, ",", $ip_obj->{src_ip +}, ":", $tcp_obj->{src_port}, " -> ", $ip_obj->{dest_ip}, ":", $tcp_o +bj->{dest_port}, "\n"; }

In reply to Getting ethernet type using NetPacket by merrittr

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.