I'm a novice to PERL and I need to finish writing this for my project in a week. I've written to the following code for Snort rule base.What the program is supposed to do is this. Go to Snort folder in C: drive.In that folder, there will be another folder called "rules", in which there will be files by the extension ".rules". I've to extract only the header part of the file. A rule file can be divided into two types: 1) Rule header and 2) Rule options. I'm interested only in rule header. It begins with the beginning of the file (And most of the times the first word is "Alert") till the first opening bracket is encountered. I want to extract only the header part,convert it to hex (using sprintf and ord)and save it to a file called "camdata.txt".Before including use warnings and use strict,I was getting errors related to scalar found where operator expected. Now I get $rulefile requires explicit package name
use strict; use warnings; # use dignostics; print "RULE_FILE : $rulefile \n"; $rulesdir="C:\\Snort\\rules\\*.rules"; @rulefiles = `ls $rulesdir\/*.rules`; $camfile = "camdata.txt"; # print "RULE_FILE : $rulefile \n"; for $rulefile(@rulefiles){ open(INFILE, "<".$rulefile) or die "Can't open ".$rulefile."\n"; @rules=<INFILE>; close(INFILE); # $headerParts = 0; # why bhave I taken a header part here? # $headerParts++; for($rule =~ /alert/) # $prule = $rule; $prule = substr($prule, 0, index($prule, '(')); print "extracted header : $prule \n"; } # Store header-part # if ($headerParts == 1){ # push(@prules, $prule); }
In reply to Scanning multiple files from Snort rules one by one and extracting a particular part to another file - File Handling by edison.pioneer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |