Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: converting tcpdump output

by brian_d_foy (Abbot)
on May 16, 2005 at 04:11 UTC ( [id://457359]=note: print w/replies, xml ) Need Help??


in reply to converting tcpdump output

I wrote a little script to do this for me. You might be able to adapt it more easily.

--
brian d foy <brian@stonehenge.com>

Replies are listed 'Best First'.
Re^2: converting tcpdump output
by RnC (Sexton) on May 16, 2005 at 04:53 UTC
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://457359]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-23 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found