Click here to get back home

Net::Analysis Parse tcpdump for HTTP Request/Response Headers

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Net::Analysis Parse tcpdump for HTTP Request/Response Headers raja.osu 07-29-2007
Posted by raja.osu on July 29, 2007, 6:41 am
Please log in for more thread options


Hi,

Iam pretty new to Perl. I have a requirement of parsing tcpdump file
to extract HTTP Request/Response headers, corresponding to successful
requests that have query strings. This, I have done using the
Net::Analysis package. But I have the additional requirement of
writing out the headers to different files based on the server program
being requested (like...all requests/responses corresponding to
example.com/login.pl, should go to one file).

I realised that the command:
perl -MNet::Analysis -e main HTTP Example3.pm tcpdump.file

invokes the .pm file for each line of the dump file. I was initially
thinking of opening one file handle for each unique server program and
writing the headers accordingly...But if the .pm file is invoked per
line of the input file, this does not seem possible. Iam very new to
Perl and am not able to think of the best way to get this done. Could
you please help me out in this regard? I have pasted below the simple
parser which reads the tcpdump file and prints out the request/
response headers for successful requests with query strings.

Thanks a lot,
Raja


=============================================
use strict;
use warnings;
use base qw(Net::Analysis::Listener::Base);
use URI;
use URI::QueryParam;

sub http_transaction {
my ($self, $args) = @_;
my ($req) = $args->; # isa HTTP::Request
my ($resp) = $args->; # isa HTTP::Response
my $u;

# if ( $args-> ) { printf "%s\n", $req->as_string; }
# if ( $args-> ) { printf "%s\n", $resp-
>headers_as_string; }

if ( $args-> && $args-> && (lc($req->method) eq "get"))
{
$u = URI->new($req->uri, "http");
if ( $u->query && ($resp->code >= 200 && $resp->code < 300))
{
print $req->as_string,"\n";
print $resp->headers_as_string,"\n";
print "Method: ", $req->method,"\n";
print "URI: ", $req->uri,"\n";
print "QUERY: ", $u->query,"\n";
for my $key ($u->query_param) {
print "$key: ", join(", ", $u->query_param($key)), "\n";
}
}
}
}

1;
=============================================


Similar ThreadsPosted
Parse tcpdump for HTTP Request Response Headers July 29, 2007, 2:10 pm
http request headers October 1, 2004, 12:47 pm
http headers with CGI.pm and mod_perl (bug?) November 10, 2004, 10:19 pm
Problem to get Parse::Yapp and Parse:Flex working together November 2, 2005, 3:15 pm
time-series analysis using Math::FFT October 7, 2006, 4:41 pm
Parse::Readelf 0.01 - parse the output of readelf September 24, 2007, 12:07 pm
XML::Twig parseurl with input Headers/XML January 16, 2005, 10:58 pm
Premature Ending of script headers August 17, 2005, 4:53 pm
Problem with CPAN and tar file headers May 16, 2007, 4:57 am
HTML::TableExtract with headers constraint, exluding right-most column May 15, 2005, 3:31 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap