Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Heelp!! Script ... PCAP file ...

by gman (Friar)
on Dec 07, 2009 at 03:05 UTC ( [id://811413]=note: print w/replies, xml ) Need Help??


in reply to Heelp!! Script ... PCAP file ...

Hello,

Your code does not run as is, there are errors. A simple add of an if condition is all i believe you are looking for. For testing I removed the writing to the file and printed to screen. I assumed your configuration file will only contain one set of IP constraints. Also removed the $i counter, looks like it should have been a global variable.

#!/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 $!; sub process_pkt { my ($user, $hdr, $pkt) = @_; my $ip_obj = NetPacket::IP->decode(eth_strip($pkt)); my $eth_obj = NetPacket::Ethernet->decode($pkt); if($ip_obj->{src_ip} eq $config{'SourceIP'}) { print "SourceIP : $ip_obj->{src_ip}\n"; print "SourceMAC : $eth_obj->{src_mac}\n"; print "EthernetType : $eth_obj->{type}\n"; print "IPProtocol : $ip_obj->{proto}\n"; print "----------------------------\n"; } } 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 +not open file...$err\n"; Net::Pcap::loop($pcap, -1, \&process_pkt, ''); Net::Pcap::close($pcap); close FILE, ">$file" or die "unable to close $file $!";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://811413]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-29 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found