in reply to simple perl sniffer
Here's a simple example of a script that sniffs an ethernet line for all TCP/IP packets bound to/from a particular host and dumps out the source/destination IP address/port and a hex dump of the packet's contents:
#!/usr/bin/perl -w use strict; use Net::PcapUtils; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::TCP; use Data::HexDump; Net::PcapUtils::loop(\&process_pkt, FILTER => 'ip host 192.168.1.252') +; my $i=0; sub process_pkt { my ($user_data,$hdr,$pkt)=@_; my $eth=NetPacket::Ethernet->decode($pkt); if($eth->{type} == 2048){ my $ip=NetPacket::IP->decode($eth->{data}); if($ip->{proto} == 6){ my $tcp=NetPacket::TCP->decode($ip->{data}); print "\n\n$i $ip->{src_ip}($tcp->{src_port}) -> $ip->{dest_ip}( +$tcp->{dest_port})\n"; print HexDump $ip->{data}; $i++; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: simple perl sniffer
by Anonymous Monk on May 09, 2000 at 21:43 UTC | |
|
RE: RE: simple perl sniffer
by marcos (Scribe) on May 09, 2000 at 19:45 UTC | |
by rob_au (Abbot) on Sep 04, 2002 at 11:25 UTC | |
by lhoward (Vicar) on May 10, 2000 at 07:29 UTC | |
|
Re^2: simple perl sniffer
by Anonymous Monk on Jan 24, 2006 at 14:48 UTC | |
by lhoward (Vicar) on Jan 26, 2006 at 13:05 UTC | |
|
Re^2: simple perl sniffer
by Anonymous Monk on May 29, 2012 at 00:36 UTC |