Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl TCP sniffer

Status
Not open for further replies.

awolff01

Programmer
Joined
Jun 17, 2003
Messages
55
Location
US
Hello,

I am wondering if anybody knows of a network sniffer for perl?

I need to log network traffic going out of my machine thru my tcp ports to get the exact syntax of cgi call my browser is making.

Thanks.
 
You can use the Net::PcapUtils and NetPacket modules to build a primitive sniffer in perl.

Here is a quick http sniffer in perl (modified from NetPcket::TCP man page):

Code:
#!/usr/bin/perl -w

use strict;
use Net::PcapUtils;
use NetPacket::Ethernet qw(:strip);
use NetPacket::IP qw(:strip);
use NetPacket::TCP;

sub process_pkt {
  my($arg, $hdr, $pkt) = @_;

  my $tcp_obj = NetPacket::TCP->decode(ip_strip(eth_strip($pkt)));

  if (($tcp_obj->{dest_port} == 80)) {
    print($tcp_obj->{data});
  }
}

Net::PcapUtils::loop(\&process_pkt, FILTER => 'tcp');
Your platform must support libpcap to use the Net::Pcap and Net::PcapUtils modules.

Hope that helps.
 
...sounds like you just need to monitor port 80 rather than write your own sniffy thingy. How about tcpdump (
"As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilkes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top