Hi Team! I was on Christmas break so just got back and found your amazing answers! THANK YOU SO MUCH!
I have adjusted the script according to your collective feedback and I also realised I need to explain a bit more what I am trying to do
I have two files; one file with all my interesting IPs in it; and another file with all the firewall rules in it.
I need to sift through the firewall rules and PRINT THE ENTIRE FW RULE LINE in the FW rules file if it matches any of the IPs in the interesting IP address file.
My interesting IP file:
1.1.1.1
2.2.2.2
10.198.0.0
3.3.3.3
10.198.1.0
My FW rules file:
133 bba33132-6192-51e8-4d78-c1b7bfd47251 any V072-AklC-DB MOSSACSQLAdm
+inGroup 10.198.0.0/16 10.210.0.0/16 MOSS_SQLAD_10-208-22-1/28 accept
+ always RDP TCP17338 TCP18230 PING all change 125213 157309
+
136 a5ea4ee8-6192-51e8-0252-2017208af83d any V071-AklC-Web ACHenderson
+RDPUsers 10.198.1.0/16 10.210.0.0/16 MOSS_InternalWeb_10-208-22-16/28
+ accept always FTP all
My adjusted script:
use strict;
use warnings;
use Regexp::Common qw( net );
open ( IPS, '<', "TEST_IPS.txt" ) || die "can't open IPS!";
open ( RULES, '<', "test_rules.txt" ) || die "can't open file!";
my %interesting_ips;
while( <IPS> ) {
chomp;
$interesting_ips{ $_ } = 1;
}
while( my $fw_line = <RULES> ) {
while( my( $addr ) = $fw_line =~ m{($RE{net}{IPv4})}g ) {
print ( $fw_line);
}
}
When I run the script, two things happen:
1. It only matches the first match and never moves on to the second match, and
2. It does not exit and I have to ctrl+c to get it to stop filling the screen with the first match
What am I doing wrong please?
I can repay the help in honey from my backyard beehives. It's very very yummy!
|