gk2010 has asked for the wisdom of the Perl Monks concerning the following question:
... my $object = Net::Pcap::open_live($dev, 1024, 1, 0, \$err); ... sub token_data { my $data = shift; my @items = split (/\n|\r\n|\r/,$data); my $item; my $host = ''; my $uri = ''; foreach $item (@items) { if ($item =~ /GET\s+(.*)\s+HTTP.*/) { $uri= $1; } if ($item =~ /Host:\s+(.*)/) { $host = $1; } if ($item =~ /User-Agent:\s+(.*)/) { $agent = $1; $agent =~ s/\(//g; $agent =~ s/\)//g; } } return "$host,$uri,$agent"; } sub process_packet { my($user_data, $header, $pkt) = @_; my $ether_data = NetPacket::Ethernet::strip($pkt); my $ip = NetPacket::IP->decode($ether_data); my $tcp = NetPacket::TCP->decode(ip_strip(eth_strip($pkt))); if ($tcp->{data} =~ /GET|POST|get|post/) { if ($tcp->{data} =~ /.*Host:\s+(.*)/) { my $result = token_data ($tcp->{data}); print "DEBG::$ip->{'src_ip'},$ip->{'dest_ip'},$tcp->{'de +st_port'},$result\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: libpcap, netpacket and decoding http data
by Illuminatus (Curate) on Mar 17, 2010 at 15:42 UTC | |
by gk2010 (Initiate) on Mar 17, 2010 at 15:49 UTC | |
|
Re: libpcap, netpacket and decoding http data
by Corion (Patriarch) on Mar 17, 2010 at 14:59 UTC | |
by gk2010 (Initiate) on Mar 17, 2010 at 15:20 UTC | |
by Corion (Patriarch) on Mar 17, 2010 at 15:23 UTC | |
by gk2010 (Initiate) on Mar 17, 2010 at 15:55 UTC | |
by Corion (Patriarch) on Mar 17, 2010 at 15:58 UTC | |
|