I am picking up IP address from a ifcfg file (RHEL) and trying to validate IP. But I am not able to validate it. When I am using IP address in quotes (e.g. ipaddress = "x.x.x.x" to check) it works but when I am trying to take it dynamically it does not
#!/usr/bin/perl use strict; use warnings; use Data::Validate::IP qw(is_ipv4); print "Enter the absolute directory location for ifcfg files\n"; my $directory = <>; chomp($directory); opendir(DIR, $directory) or die "couldn't open $directory: $!\n"; my @ifcfg_files = grep { /^ifcfg-bond/ } readdir(DIR); closedir DIR; foreach (@ifcfg_files) { my %hash = (); my $file = "$_"; open (my $fh, "<", $file) or die "Can't open the file $file: "; while (my $line =<$fh>) { next if $. < 2; my($key, $parameter_value) = split("=", $line); next if $key eq "BONDING_OPTS"; if (is_ipv4($parameter_value)) { print $parameter_value; } else{ print "Fail" } } } #Outer Foreach Contents of ifcfg file # Creating bond1 DEVICE=bond1 IPADDR=172.31.1.1 NETMASK=255.0.0.0 DNS1=172.30.12.25 MTU= BOOTPROTO=none ONBOOT=yes USERCTL=NO NM_CONTROLLED=no BONDING_OPTS='mode=1 miimon=100' Result [root@localhost bond]# perl ifcfgbondverification.pl Enter the absolute directory location for ifcfg files /root/office/ifcfgverification/bond FailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFa +ilFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFai +lFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFail +FailFailFailFailFailFailFailFailFailFailFail[root@localhost bond]#
In reply to IP address validation when IP is picked dynamically by rahulruns
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |