Hi all,
When I execute the following code, it's captures all the data going trough my network card, that goes fine. But then i want to print the headers of the packets, see the if-statement:
-
if (index($packet,"GET" gt 0)) {
-
$start = (index($packet,"GET"));
-
$end = (index($packet,"Content-Length: "));
-
-
} else {
-
$start = (index($packet,"POST"));
-
$end = length($packet);
-
}
-
When the HTTP POST method is used, it has to print the whole header, including the POST variables. So the $end is just the lenght of the whole packet. When the GET method is used, I only want to have the header, until "Content-Length" or so. But, when i execute this, it will only print the GET requests. When i swap the POST en GET in the if-statement, it will only display the POST requests. Like so:
-
if (index($packet,"POST" gt 0)) {
-
$start = (index($packet,"POST"));
-
$end = length($packet);
-
-
} else {
-
$start = (index($packet,"GET"));
-
$end = (index($packet,"Content-Length: "));
-
-
}
-
I don't get this behavior, and it's driving me crazy, because I've tried alot of things..
Is there anyone who can help me out? Thanks in advance!!!
The whole script:
[/code]
-
#!/usr/bin/perl -w
-
use strict;
-
use Net::PcapUtils;
-
$,=' ';
-
my $start;
-
my $end;
-
-
my $error = Net::PcapUtils::loop(\&print_packet);
-
die $error if $error;
-
-
sub print_packet {
-
-
my($user_data, $header, $packet) = @_;
-
-
if (index($packet,"HTTP") gt 0){
-
-
if (index($packet,"GET" gt 0)) {
-
$start = (index($packet,"GET"));
-
$end = (index($packet,"Content-Length: "));
-
-
} else {
-
$start = (index($packet,"POST"));
-
$end = length($packet);
-
}
-
-
print substr ($packet, $start,($end-$start))."\n";
-
-
}
-
}
-