Re: Restrict IP access to a Perl application



barramundi9 <barramundi9@xxxxxxxxxxx> wrote:

open(FILE,"/path/to/ip.allow") or die ("Cannot open file!");
flock(FILE,2);
while ($line=<FILE>) {
$line=~s/\./\\\./g;

You replace '.' with '\.' in $line...

if ($line =~ /$address/) {

....so now you're matching: "10\\.0\\.0\\.1\n' =~ /10.0.0.1/
which obviously fails since there are no backslashes in $address.

I suspect you meant this to be:
if ( $address =~ /$line/ ) {
which would still fail since there is no "\n" in $address.

In which case you could use chomp and also get rid of the s///
and use \Q in your match:
chomp $line;
if ( $address =~ /\Q$line/ ) {

or, better yet, use chomp() and eq
chomp $line;
if ( $line eq $address ) {

.