Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
-------------------------------------------- Then I have a PCAP file with information about packets from a network capture. In the script I need to compare the field from txt with the header of all packets and, if some match, show that packet. Now my scrip is something like this: Script.plSourceIP = 10.1.1.1 SourceMAC = 00d0047203fc IPProtocol = 7
------------------------------------------------------------------------------- Please, I need help!! Regards ...Chocolataria#!/usr/bin/perl -w use strict; use warnings; use Net::PcapUtils; use Net::Pcap; use NetPacket::Ethernet qw(:strip); use NetPacket::IP; #use Config::Reader::Simple; my $file = "CaptureData.txt"; open FILE, ">$file" or die "unable to open $file $!"; my %config; open my $config, '<', 'Config.txt' or die $!; while(<$config>) { chomp; my ($key, $value) = split /\s*=\s*/, $_; $config{$key} = $value; print FILE "chave: $key -- valor: $value\n"; } my $err =''; my $i = 1; my $pcap = Net::Pcap::open_offline("capture.pcap", \$err) or die "Can' +t open file...$err\n"; Net::Pcap::loop($pcap, -1, \&process_pkt, ''); Net::Pcap::close($pcap); sub process_pkt { my ($user, $hdr, $pkt) = @_; my $ip_obj = NetPacket::IP->decode(eth_strip($pkt)); my $eth_obj = NetPacket::Ethernet->decode($pkt); print FILE "$i\n"; print FILE "SourceIP : $ip_obj->{src_ip}\n"; print FILE "SourceMAC : $eth_obj->{src_mac}\n"; print FILE "EthernetType : $eth_obj->{type}\n"; print FILE "IPProtocol : $ip_obj->{proto}\n"; print FILE "----------------------------\n"; $i++; } close FILE, ">$file" or die "unable to close $file $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Heelp!! Script ... PCAP file ...
by gman (Friar) on Dec 07, 2009 at 03:05 UTC | |
|
Re: Heelp!! Script ... PCAP file ...
by Anonymous Monk on Dec 06, 2009 at 03:22 UTC | |
by Anonymous Monk on Dec 06, 2009 at 16:26 UTC | |
by Anonymous Monk on Dec 07, 2009 at 10:45 UTC |