in reply to Catching the command sent by an Internet Button
The Net::Pcap, Net::PcapUtils and NetPacket module provides this kind of functionality. However, they will only parse the network layers. You're gonna have to assemble the packets and parse the HTTP headers yourself.
Here is some sample code that uses those modules to build a simple sniffer that dumps out all HTTP packets (port 80) to the screen. You must be root to run Pcap utilities since they have to open network interfaces in promiscuous mode.
#!/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 => 'port 80'); 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++; } } }
|
|---|