I'm a Perl newbie and I have a job to do, but I can't do that! I'm almost crying! =(
Please, someone help me?

This is my problem:
I have a txt file like this

SourceIP =
SourceMAC = 00d0047203fc
IPProtocol = 7
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:

#!/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 $!;

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, '');


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";

close FILE, ">$file" or die "unable to close $file $!";

Please, I need help!!


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.