[ADVANCED] NET:PcapUtils problem driving me nuts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • heaveninflames
    New Member
    • Oct 2008
    • 4

    [ADVANCED] NET:PcapUtils problem driving me nuts

    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:

    Code:
    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:

    Code:
    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]


    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";
    
    }
    }
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    do you want to use ">" instead of "gt"?

    Comment

    Working...