Hi brian,

I modified your script to match my local config ("eth0" instead of "en1", removed "or src port 80" since I don't need that, and ran it as root directly, so no need for sudoing before). However, I got no output when using it. Here's what I have:
#!/usr/bin/perl use strict; my( $header, $packet ) = ('', ''); open STDIN, "/usr/sbin/tcpdump -lx -s 1024 dst port 80 |"; #die "Could not open tcpdump" unless $?; while( <> ) { chomp; if( /^\S+/ ) { print_packet( $header, $packet ); $header = $_; $packet = undef; next; } $packet .= $_; } sub print_packet { my( $header, $packet ) = @_; $packet =~ s/\s//g; $packet =~ s/.{104}//; # remove protocol info return unless length $packet > 0; $packet =~ s/0d0a0d0a.*/0d0/i; # Just keep the HTTP header my $pretty = ''; BYTE: while( $packet =~ m/\G([0-9a-f]{2})\s*/ig ) { my $hex = hex $1; if( $hex == 0x0D ) { $pretty .= "\n"; next BYTE } if( $hex == 0x0A ) { next BYTE } $pretty .= do { if( $hex < 0x20 or $hex > 0x7f ) { '.' } else { chr $hex } }; } if( $pretty =~ m/^(?:HTTP|GET|POST)/ ) { print_header( $header ); print $pretty; } return length $packet; } sub print_header { my $header = shift; my ( $time, $src, undef, $dst, ) = split /\s+/, $header; $time =~ s/\..*//; $dst =~ s/:$//; print "-" x 73, "\n"; print "Time: $time Src: $src Dst: $dst\n"; }

Cheers.

In reply to Re^2: converting tcpdump output by RnC
in thread converting tcpdump output by RnC

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.