Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Read() -Multiple Files-

by Corion (Pope)
on Jan 26, 2012 at 16:08 UTC ( #950152=note: print w/replies, xml ) Need Help??

in reply to Read() -Multiple Files-

Do you want to pass the filename on the command line? If so, see perlvar on @ARGV.

Do you want to add all files matching some wildcard? If so, see File::Glob on bsd_glob:

use File::Glob qw(bsd_glob); my @files = bsd_glob("C:\\Documents and Settings\\jordant\\Desktop\\Du +mp\\*.pcap"); for my $file (@files) { print "Processing '$file'\n"; };

Replies are listed 'Best First'.
Re^2: Read() -Multiple Files-
by jboy4 (Initiate) on Jan 26, 2012 at 17:06 UTC

    Could someone help integrating the above methods into my code? I am having issues getting either to work

    Here is the first one. Did i put something in wrong?
    #!/usr/bin/perl use DBI; use Net::TcpDumpLog; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::TCP; use Net::Pcap; use strict; use warnings; use File::Glob qw(bsd_glob); #Login to mysql my $dbh = DBI->connect('DBI:mysql:test', 'root', 'nstar' ) || die "Could not connect to +database: $DBI::errstr" +; #Pcap file to log my $log = Net::TcpDumpLog->new(); my @files = bsd_glob("C:\\Documents and Settings\\jordant\\Desktop\\D +ump\\*.pcap"); $log->read('$file'); for my $file (@files) { print "Processing '$file'\n"; }; #INFO from PCAP file foreach my $index ($log->indexes) { my ($length_orig, $length_incl, $drops, $secs, $msecs) = $log->header +($index); my $data = $log->data($index); my $eth_obj = NetPacket::Ethernet->decode($data); next unless $eth_obj->{type} == NetPacket::Ethernet::ETH_TYPE_IP; my $ip_obj = NetPacket::IP->decode($eth_obj->{data}); next unless $ip_obj->{proto} == NetPacket::IP::IP_PROTO_TCP; my $tcp_obj = NetPacket::TCP->decode($ip_obj->{data}); #get date time stamp of packet my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( +$secs + $msecs/1000); $mon+=1; my $time = sprintf("%02d-%02d %02d:%02d:%02d", $mon, $mday, $hour, $min, $sec); #Info in Table $dbh->do( "INSERT INTO test2 (Date,Source,Destination,Packets +,Port) values ( '$time', '$ip_obj->{src_ip}', '$ip_obj->{dest_ip}', '$ip_obj->{len}', '$tcp_obj->{dest_port}')"); }
    Errors out: saying it cant find the directory
      Please tell us what you do, and what your program outputs and how that differs from what you expect. Also try reducing the program to the bare minimum that still shows the error. As a hint, consider where bsd_glob stores its results. This is not a code writing service.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950152]
[erix]: isn't a texty format handier for configs?
[Corion]: So far, I've avoided having even a user database by storing the user information in a (signed) cookie that the browser keeps for me, but as I want to be able to lock users, I need a second storage option :)
[Corion]: erix: It's needed for keeping the list of users and the list of tags associated with an image, and for keeping the images with users. I want an easy way to know if an image can be deleted, which means that it can't be referenced by any tag anymore. ...
[Corion]: SQL feels like a natural choice here :)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2018-03-20 14:08 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (253 votes). Check out past polls.