467,179 Members | 1,197 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,179 developers. It's quick & easy.

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

Expand|Select|Wrap|Line Numbers
  1. if (index($packet,"GET" gt 0)) {
  2.         $start = (index($packet,"GET"));
  3.         $end = (index($packet,"Content-Length: "));
  4.  
  5. } else {
  6.         $start = (index($packet,"POST"));
  7.         $end = length($packet);
  8. }
  9.  
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:

Expand|Select|Wrap|Line Numbers
  1. if (index($packet,"POST" gt 0)) {
  2.         $start = (index($packet,"POST"));
  3.         $end = length($packet);
  4.  
  5. } else {
  6.         $start = (index($packet,"GET"));
  7.         $end = (index($packet,"Content-Length: "));
  8.  
  9. }
  10.  
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]


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Net::PcapUtils;
  4. $,=' ';
  5. my $start;
  6. my $end;
  7.  
  8. my $error = Net::PcapUtils::loop(\&print_packet);
  9. die $error if $error;
  10.  
  11. sub print_packet {
  12.  
  13. my($user_data, $header, $packet) = @_;    
  14.  
  15. if (index($packet,"HTTP") gt 0){
  16.  
  17. if (index($packet,"GET" gt 0)) {
  18.         $start = (index($packet,"GET"));
  19.         $end = (index($packet,"Content-Length: "));
  20.  
  21. } else {
  22.         $start = (index($packet,"POST"));
  23.         $end = length($packet);
  24. }
  25.  
  26. print substr ($packet, $start,($end-$start))."\n";
  27.  
  28. }
  29. }
  30.  
Oct 1 '08 #1
  • viewed: 1465
Share:
1 Reply
KevinADC
Expert 2GB
do you want to use ">" instead of "gt"?
Oct 1 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Steve Johnson | last post: by
55 posts views Thread by Alex | last post: by
12 posts views Thread by Marty | last post: by
14 posts views Thread by mat | last post: by
reply views Thread by shapper | last post: by
2 posts views Thread by shapper | last post: by
5 posts views Thread by über | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.